Count Users in AD By OU

This topic contains 3 replies, has 3 voices, and was last updated by Profile photo of Chas Feller Chas Feller 8 months, 4 weeks ago.

  • Author
    Posts
  • #36318
    Profile photo of Chas Feller
    Chas Feller
    Participant

    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
    $Disabled=$total–$Enabled
    New-Object psobject -Property @{
    Name=$_.Name;
    OU=$_.Distinguishedname;
    Description=$_.Description;
    TotalUsers=$Total;
    Enabled=$Enabled;
    Disabled=$Disabled
    }
    }

  • #36319
    Profile photo of Jeremy Murrah
    Jeremy Murrah
    Participant

    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
    Profile photo of Richard Siddaway
    Richard Siddaway
    Moderator

    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
    Profile photo of Chas Feller
    Chas Feller
    Participant

    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.