Author Posts

March 9, 2016 at 8:59 am

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
}
}

March 9, 2016 at 9:05 am

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.

March 9, 2016 at 9:10 am

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

March 9, 2016 at 9:33 am

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