Based on the above example, why would the result of the above not be 'On'? I'm feeling rather foolish because this is so simple but in any other language $PowerStateMap[$DeviceStatus.PowerState] would have returned 'On'. Does PowerShell have some weird trick for referencing a hashtable?
Update: I figured it out... I had to typecast $DeviceStatus.PowerState to an int manually. Why did I have to do that?
Edit: For reference:


$DeviceStatus.Powerstate.gettype()?$PowerStateMap[[int]$DeviceStatus.PowerState]Hashtableis not generic; it usesobjectkeys. Unfortunately the .NET equality rules make it so that a boxedInt64is not ever considered identical to a boxedInt32, no matter their values. This is a leaky abstraction; PowerShell doesn't really "do" anything with boxing, but it suffers the consequences anyway.