Running this script returns all of the users with any value populated for the LogOnHours attribute but it ignores the $All_Hours variable as users with that value ARE returned. The goal is to ignore any users who have the LogOnHours set to 24 hour access. Where am I going wrong here? Any help is greatly appreciated.
[byte[]]$All_Hours = @(255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255)
$ADSISearcher = [ADSISearcher]'(objectclass=user)'
$ADSISearcher.SearchRoot = [ADSI]"LDAP://OU=test,DC=test,DC=local"
$ADSISearcher.FindAll()| ForEach-Object {
$user = [adsi]$_.Properties.adspath[0]
if ($user.logonHours -ne $null -and $user.logonhours -ne $All_Hours) {
New-Object -Type PSCustomObject -Property @{
SamAccountName = $user.sAMAccountName[0]
LogOnHours = $user.logonHours
}
}
}