It looks like you're adding 32 or 0x20 to the second byte to turn it on:
$myval[1] += 32 # on
$myval[1] -= 32 # off
Bitwise, "or" to set, "and" with "bit complement (not)" to unset.
0x1e -bor 0x20 # on
62
0x3e -band -bnot 0x20 # off
30
Maybe you could make a flags enum for all the settings, but you'd have to convert the byte array to one large int.
EDIT: Oh, if you just want to check that a bit is set:
$shadowbit = 0x20
if (0x3e -band $shadowbit ) { 'yep' } else { 'nope' } # 32
yep
if (0x1e -band $shadowbit ) { 'yep' } else { 'nope' } # 0
nope
See also How do you set, clear, and toggle a single bit?
EDIT:
I went a little overboard. Having this in preperation:
[Flags()] enum UserPreferencesMask {
ActiveWindowTracking = 0x1
MenuAnimation = 0x2
ComboBoxAnimation = 0x4
ListBoxSmoothScrolling = 0x8
GradientCaptions = 0x10
KeybordCues = 0x20
ActiveWindowTrackingZOrder = 0x40
HotTracking = 0x80
Reserved8 = 0x100
MenuFade = 0x200
SelectionFade = 0x400
ToolTipAnimation = 0x800
ToolTipFade = 0x1000
CursorShadow = 0x2000 # 13
Reserved14 = 0x4000
Reserved15 = 0x8000
Reserved16 = 0x10000
Reserved17 = 0x20000
Reserved18 = 0x40000
Reserved19 = 0x80000
Reserved20 = 0x100000
Reserved21 = 0x200000
Reserved22 = 0x400000
Reserved23 = 0x800000
Reserved24 = 0x1000000
Reserved25 = 0x2000000
Reserved26 = 0x4000000
Reserved27 = 0x8000000
Reserved28 = 0x10000000
Reserved29 = 0x20000000
Reserved30 = 0x40000000
UIEffects = 0x80000000 # 31
}
You can do:
$myVal = get-itemproperty 'HKCU:\Control Panel\Desktop' UserPreferencesMask |
% UserPreferencesMask
$b = [bitconverter]::ToInt32($myVal,0)
'0x{0:x}' -f $b
0x80073e9e
[UserPreferencesMask]$b
MenuAnimation, ComboBoxAnimation, ListBoxSmoothScrolling,
GradientCaptions, HotTracking, MenuFade, SelectionFade,
ToolTipAnimation, ToolTipFade, CursorShadow, Reserved16, Reserved17,
Reserved18, UIEffects
[UserPreferencesMask]$b -band 'CursorShadow'
CursorShadow
if ([UserPreferencesMask]$b -band 'CursorShadow') { 'yes' }
yes
Note that 3 undocumented reserved bits are already in use in my Windows 10. This is with "show shadows under mouse pointer" checked under "performance options" (advanced system) in the control panel
OR, getting simple without the enums:
$b = [bitconverter]::ToInt32($myVal,0) # 4 bytes from reg_binary to int
if ($b -band [math]::pow(2,13)) { 'cursor shadow' }
I've noticed that that registry entry is actually 8 bytes long, but bringing in all 8 bytes doesn't change the answer, even if some of those extra bits are set in windows 10.