Powershell - Count AD users
-
I don't do PS,... but I need a script to count the number of AD users,.... I've tried several but they all error - LIKELY since I don't know PS and am not keying the sting values (verb-noun) correctly..
-
We will need to see the script and the command to know what to fix.
-
Ah - okay ... found this that works...
(Get-ADUser -filter *).count
Gives total count of AD accounts - Windows and Users.
-
Try this one?
(Get-ADUser -filter * -searchbase "OU=Vancouver, OU=MyCompany, DC=Domain, DC=Local").count
the AD has two OUs, Both OUs are two words with (space).
-
Gonna try to edit this and see...
https://gallery.technet.microsoft.com/scriptcenter/Powershell-script-to-5edcdaea
-
@gjacobse This one works. But you can take a look at this From Neally.
https://community.spiceworks.com/topic/1926864-counting-all-enabled-and-disabled-users-in-ad
Pretty neat. -
@dbeato said in Powershell - Count AD users:
@gjacobse This one works. But you can take a look at this From Neally.
https://community.spiceworks.com/topic/1926864-counting-all-enabled-and-disabled-users-in-ad
Pretty neat.Where is my bottle of bleach? SW - Really? jK - thanks will look at that now.
-
Here it is so you don't need to go there
$allDisabldAccounts = (Search-ADAccount -AccountDisabled).count Write-Output "Disabled accounts:`t`t $allDisabldAccounts" $all = (get-aduser -Filter *).count $allactive = $all - $allDisabldAccounts Write-Output "Active Accounts:`t`t $allactive" Write-Output "All Accounts:`t`t`t $all"
-
@dbeato said in Powershell - Count AD users:
$allDisabldAccounts = (Search-ADAccount -AccountDisabled).count
Write-Output "Disabled accounts:t
t $allDisabldAccounts"
$all = (get-aduser -Filter *).count
$allactive = $all - $allDisabldAccounts
Write-Output "Active Accounts:t
t $allactive"
Write-Output "All Accounts:t
t`t $all"Yup,.. nice.
Thank youDisabled accounts: 11
Active Accounts: 201
All Accounts: 212 -
Yeah, it works nice, you can use the filter of your OU if you want too.
-
@dbeato said in Powershell - Count AD users:
Yeah, it works nice, you can use the filter of your OU if you want too.
Thanks - I can already see that I want to do more with it. But I didn't need that level tonight. Maybe next week when I have more time... yea.. like THAT will happen.
-
@gjacobse said in Powershell - Count AD users:
I don't do PS,... but I need a script to count the number of AD users,.... I've tried several but they all error - LIKELY since I don't know PS and am not keying the sting values (verb-noun) correctly..
Or, open up Active Directory Users and Computers, right-click on your domain, click find.
In the find window, specify only users to search for, then click the Find button. There will be a count at the bottom.
(if there wasn't a specific reason to use PowerShell)
-
You can try the following command:
(get-aduser -filter *).count
For only Enabled User Accounts
(get-aduser -filter *|where {$_.enabled -eq "True"}).countFor only Disabled User Accounts
(get-aduser -filter *|where {$_.enabled -ne "False"}).count