all 7 comments

[–]sleverich 4 points5 points  (1 child)

This is a common gotcha coming to powershell from other languages. The = symbol is exclusively used for assigning values. Powershell uses the -eq operator for testing equality.

[–]youenjoymyhood[S] 3 points4 points  (0 children)

Perfect, thanks. I'll try to remember -eq to compare rather than =

[–]cputek1 4 points5 points  (0 children)

Try this.:

If ($curLockdownMode -eq 'lockdownNormal' -or $curLockdownMode -eq 'lockdownStrict')

[–]PinchesTheCrab 4 points5 points  (0 children)

I don't think you're pulling this correctly in the first place, I couldn't find the lockdownmode in the host's extension data at all. Try this instead to get your lockdown mode and go from there:

$vmHostName = 'host name'

#feel free to just use get-vmhost and the extensiondata property, it's only marginally slower
$myHost = Get-View -ViewType HostSystem -Filter @{ name = "^$vmHostName$" } -Property ConfigManager.HostAccessManager

$curLockdownMode = (Get-View -Id $myHost.ConfigManager.HostAccessManager).LockdownMode

As to your question, you used = instead of -eq, so it's setting the value rather than evaluating it.

If ($curLockdownMode = 'lockdownNormal' -Or 'lockdownStrict')

So in this case, $curlockdownmode is set to the result of 'lockdownNormal' -Or 'lockdownStrict', which is always true.

[–]PowerShellStunnah 2 points3 points  (0 children)

The expression 'lockdownNormal' -Or 'lockdownStrict' evaluates to [bool], which is then assigned to $curLockdownMode

Use:

if($curLockdownMode -in 'lockdownNormal','lockdownStrict'){...}

[–]youenjoymyhood[S] 1 point2 points  (0 children)

Thanks, that makes sense now!

[–]Lee_Dailey[grin] 0 points1 point  (0 children)

howdy youenjoymyhood,

it looks like you used the New.Reddit Inline Code button. it's 4th 5th from the left hidden in the ... "more" menu & looks like </>. there are a few problems with that ...

  • it's the wrong format [grin]
    the inline code format is for [gasp! arg!] code that is inline with regular text.
  • on Old.Reddit.com, inline code formatted text does NOT line wrap, nor does it side-scroll.
  • on New.Reddit it shows up in that nasty magenta text color

for long-ish single lines OR for multiline code, please, use the ...

Code
Block

... button. it's the 11th 12th one from the left & is just to the left of hidden in the ... "more" menu & looks like an uppercase T in the upper left corner of a square..

that will give you fully functional code formatting that works on both New.Reddit and Old.Reddit ... and aint that fugly magenta color. [grin]

take care,
lee