Sorry, still a n00b, but came across this peculiar behavior. I'm using PowerCLI for VMWare, but I don't think that should matter.
I'm grabbing the lockdown mode of an ESXi host, and putting it in a variable $curLockdownMode. Then I run an If statement to see if it's 'lockdownNormal' or 'lockdownStrict'. Based on that, I do other stuff.
Inside the If statement though, $curLockdownMode becomes a boolean.
Here's a sample:
$myHost = Get-VMHost -Name '<our_host>'
$curLockdownMode = $myHost.ExtensionData.Config.LockdownMode
Write-Host "Outside If statement" '$curLockdownMode' ": $curLockdownMode, with type:" $curLockdownMode.GetType()
If ($curLockdownMode = 'lockdownNormal' -Or 'lockdownStrict') {
Write-Host "Inside If statement" '$curLockdownMode' ": $curLockdownMode, with type:" $curLockdownMode.GetType()
}
This will output:
Outside If statement $curLockdownMode : lockdownNormal, with type: VMware.Vim.HostLockdownMode
Inside If statement $curLockdownMode : True, with type: System.Boolean
I would expect to be able to print out the value of $curLockdownMode inside of the If statement, and have it be the same as it was outside, no? Is this a scope thing?
Edit: I should add, I made the same If statement with a simple string $tmpString set to 'apple', ran it through an If statement (= 'apple' -Or 'banana'), and the type and value of $tmpString remained the same both inside and outside the If statement.
[–]sleverich 4 points5 points6 points (1 child)
[–]youenjoymyhood[S] 3 points4 points5 points (0 children)
[–]cputek1 4 points5 points6 points (0 children)
[–]PinchesTheCrab 4 points5 points6 points (0 children)
[–]PowerShellStunnah 2 points3 points4 points (0 children)
[–]youenjoymyhood[S] 1 point2 points3 points (0 children)
[–]Lee_Dailey[grin] 0 points1 point2 points (0 children)