1
votes

I have a problem where ISE is not doing the same like the console (console does it wrong) and it is very easy to reproduce in a domain environment on a Server 2016 Domain Controller or a Server 2016 Memberserver with installed ActiveDirectory module.

c:\temp\main.ps1

Import-Module c:\temp\functions.psm1 -Force
$ObjAdDomain = Get-VarObjAdDomain
$ObjAdDomainPdc = Get-VarStrPDCEmulator
write-host "PDC = $ObjAdDomainPdc"

c:\temp\functions.psm1

function Get-VarObjAdDomain {Get-ADDomain}
function Get-VarStrPDCEmulator {$ObjAdDomain.PDCEmulator}

The expected result is, that Powershell made an output like PDC = server.domain.local in ISE and in console, but it does only in ISE. In console the output is only PDC = and the variable $ObjAdDomainPdc is empty.

This code was working without any problems at Server 2012 R2 but now with Server 2016 it isn't working anymore, but Set-StrictMode -Version 2.0 has no effect.

I know that I could run the Get-VarStrPDCEmulator and give the variable $ObjAdDomain to the function, but this is normally not necessary and I would have to change hundreds of function and generate tons of additionally code because of that (bug?).

Does anybody know what is going on here?

1
What happens if you remove the Write-Host? - Mark Kram
I don't get your question. If I remove that, there is no output. The write-host is just to see whats in the variable. - Johnny
This is a debuging step. - Mark Kram

1 Answers

0
votes

I think I figured it out.

I don't know why this script behavior is different between Server 2012R2 and Server 2016 or between ISE and console, but since I changed all variables from

"$ObjAdDomain = ..."

to

"$global:ObjAdDomain = ..."

the script is working again.