Returns the allowed logon hours for the MyerKen Active Directory user account.
On Error Resume NextDim arrLogonHoursBytes(20)Dim arrLogonHoursBits(167)arrDayOfWeek = Array _("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat")Set objUser = GetObject _("LDAP://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com")arrLogonHours = objUser.Get("logonHours")For i = 1 To LenB(arrLogonHours)arrLogonHoursBytes(i-1) = AscB(MidB(arrLogonHours, i, 1))WScript.Echo "MidB returns: " & MidB(arrLogonHours, i, 1)WScript.Echo "arrLogonHoursBytes: " & arrLogonHoursBytes(i-1)wscript.echo vbcrlfNextintCounter = 0intLoopCounter = 0WScript.echo "Day Byte 1 Byte 2 Byte 3"For Each LogonHourByte In arrLogonHoursBytesarrLogonHourBits = GetLogonHourBits(LogonHourByte)If intCounter = 0 ThenWScript.STDOUT.Write arrDayOfWeek(intLoopCounter) & Space(2)intLoopCounter = intLoopCounter + 1End IfFor Each LogonHourBit In arrLogonHourBitsWScript.STDOUT.Write LogonHourBitintCounter = 1 + intCounterIf intCounter = 8 or intCounter = 16 ThenWscript.STDOUT.Write Space(1)End IfIf intCounter = 24 ThenWScript.echo vbCrintCounter = 0End IfNextNextFunction GetLogonHourBits(x)Dim arrBits(7)For i = 7 to 0 Step -1If x And 2^i ThenarrBits(i) = 1ElsearrBits(i) = 0End IfNextGetLogonHourBits = arrBitsEnd Function
This is a VB Script, this can be used by saving the file in .vbs file