Count Users in AD By OU

This topic contains 3 replies, has 3 voices, and was last updated by  Chas Feller 2 years, 4 months ago.

  • Author
  • #36318

    Chas Feller

    I am trying to use the script form the site posted by Jeff Hicks and below and I repeatedly get the error in Powershell:–>
    Get–ADUser : The term 'Get–ADUser' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
    I am on a Server 2012R2 with AD module loaded. Do I have a version issue? I had to modify "Property to Properties" to make the first part work. What up??
    Get-ADOrganizationalUnit -Filter * -Properties DistinguishedName|
    foreach {
    $users= Get–ADUser –filter * –searchbase $_.DistinguishedName –ResultPageSize 2000 –resultSetSize 500 –searchscope Onelevel
    $total=($users | measure-object).count
    $Enabled=($users | where {$_.Enabled} | Measure-Object).count
    New-Object psobject -Property @{

  • #36319

    Jeremy Murrah

    It looks like you have some bad characters from a copy/paste. Specifically the "-" in your get-aduser is a bit too long. I copied and pasted into my ISE and got the same error. Try typing it in manually and see if that gets it to run for you.

  • #36320

    Richard Siddaway

    I don't know. I got the same error as you did. I deleted Get-ADUser out of the script and then retyped it. Worked fine after that. I suspect its an artefact of copying the script

  • #36323

    Chas Feller

    You got it. It was the "hyphen" between the get-aduser. All works correctly now. Thanks for the help.

You must be logged in to reply to this topic.