I'm making a powershell installation script for an app at work and I'm constantly switching from PowerShell ISE to PowerGUI to make it.
I found a difference between them I really can't explain and I'd like to have some advice.
For the same following code :
$test = ""
$feedback = $FALSE
try
{
$test = [System.Environment]::GetFolderPath([Environment+SpecialFolder]::ProgramFilesX86)
}
catch
{
$test = ""
}
if($test -eq "")
{
$feedback = $TRUE
}
else
{
$feedback = $FALSE
}
"Feedback : " + $feedback
"Result : " + $test
Powershell ISE returns :
Feedback : True
Result :
And PowerGUI returns :
Feedback : False
Result : C:\Program Files (x86)
Of course, C:\Program Files (x86) is an existing folder.
I'm curious to understand why. Thanks.
Your environments are not playing the same version of PowerShell, or at least the same version of the the CLR. try to look at $PSVersionTable
.
Environment.SpecialFolder enum contains ProgramFilesX86
in NET Framework 4.5 this was not the case in NET Framework 3.5 and previous versions.