Hi, I have a script that queries the A/D for accounts that are enabled:
Get-ADUser -SearchBase ‘OU=Users,OU=XXXXX,DC=XXXXX,DC=co,DC=uk’ -filter {enabled -eq “True”} | Select-Object Name,SamAccountName | Sort-Object Name | Select -Property Name,SamAccountName | Out-file -file “C:\Active Directory\Active Users.txt”
Which appears to work, but on further inspection, I have found that it is listing a few odd ‘disabled’ accounts (verified in A/D)…I even tried {enabled -eq “False”} to try and report the disabled accounts, but it misses them???
Help much appreciated
Try comparing the value on the boolean $true versus a string “True”
Get-ADUser -SearchBase 'OU=Users,OU=XXXXX,DC=XXXXX,DC=co,DC=uk' -filter {Enabled -eq $true} |
Select-Object Name,SamAccountName |
Sort-Object Name |
Out-file -file "C:\Active Directory\Active Users.txt"
Thanks for the quick response Rob!
I did try that too - and for some reason that returned the same output - I also tried $False in reverse to get disabled accounts and that also returned the same as -eq “False”…so reports are the same…but I can see the disabled accounts in A/D user OU???
sorry everyone, I forgot to format the code too here!