Need some help with Byte arrays and setting logon hours. I have these arrays:
[byte[]]$logonHoursPST = @(0,0,0,0,192,255,7,192,255,7,192,255,7,192,255,7,192,255,7,0,0) [byte[]]$logonHoursMST = @(0,0,0,0,192,255,3,192,255,3,192,255,3,192,255,3,192,255,3,0,0) [byte[]]$logonHoursCST = @(0,0,0,0,224,255,1,224,255,1,224,255,1,224,255,1,224,255,1,0,0) [byte[]]$logonHoursEST = @(0,0,0,0,240,255,0,240,255,0,240,255,0,240,255,0,240,255,0,0,0)
I then have another array that I can easily enumerate, and hopefully grab my byte array depending on the TZ entered by the user
$aryTimeZones = @( ('PST', $logonHoursPST), ('MST', $logonHoursMST), ('CST', $logonHoursCST), ('EST', $logonHoursEST) ) $TZ = Read-Host -Prompt 'Input the users Time Zone, PST, MST, CST, EST' for($i=0; $i -lt $aryTimeZones.Count; $i++) { if($aryTimeZones[$i][0] -eq $TZ) { $TZ = $aryTimeZones[$i][1] $validTZ = $True Break } }
However, when I actually try to set the logon hours, it fails (sorry, don’t recall the exact error message just now):
Set-ADUser -Identity $userName -Replace @{logonhours = $TZ}
If I use the initial array declaration, it works:
Set-ADUser -Identity $userName -Replace @{logonhours = $logonHoursPST}
Please point me to the error of my ways. Thanks in advance.