Powershell: Why does this Get-ADUser command return Nada??!

get-aduser-filter*-propertiesName,employeeID|Where-Object{$_.type -like"*user*"} |  selectName,employeeID|out-gridview

February 20th, 2015 10:03pm

get-aduser-filter*-propertiesName,employeeID|Where-Object{$_.type -like"*user*"} |  selectName,employeeID|out-gridview

At line:1 char:34
+ get-aduser-filter*-propertiesName,employeeID|Where-Object{$_.type -like"*user*"} ...
+                                  ~
Missing argument in parameter list.
At line:1 char:95
+ ... } |  selectName,employeeID|out-gridview
+                    ~
Missing argument in parameter list.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : MissingArgument
Free Windows Admin Tool Kit Click here and download it now
February 20th, 2015 10:06pm

This works:

Get-ADUser -Filter * -Properties Name,employeeID |
    Select Name,EmployeeID |
        Out-GridView

February 20th, 2015 10:08pm

Thanks Mike. However, I know that works. I put the Where-Object {$_.type -eq "User"} because the output returns a bunch of computer accounts as well.

Here's the script again...I guess copying directly from ISE got it all muddled up and hence th errors you got

get-aduser -filter * -properties Name, employeeID |

Where-Object {$_.type -eq "User" } | 

select Name, employeeID |

out-gridview

Free Windows Admin Tool Kit Click here and download it now
February 20th, 2015 10:13pm

If you really need to check, here's an adjustment:

Get-ADUser -Filter * -Properties Name,employeeID |
    Where { $_.ObjectClass -eq 'user' } |
        Select Name,EmployeeID |
            Out-GridView
February 20th, 2015 10:17pm

Thanks Mike. Was looking at objectCategory in ADSI Edit earlier and then I saw objectclass buh it just didnt seem right at the time..silly me
Free Windows Admin Tool Kit Click here and download it now
February 20th, 2015 10:29pm

Cheers, you're welcome.
February 20th, 2015 10:36pm

Get-aduser never returns computer objects.  That is why it is called Get-AdUser.

Raw ADSI will return mixed accounts if you don't use 'User" in your filter.

Free Windows Admin Tool Kit Click here and download it now
February 20th, 2015 11:12pm

In a raw ADSI search it is "objectcategory" that differentiates.

([adsisearcher]'(&(objectclass=user)(objectcategory=person))').FindAll()

If we use only objectclass=user we will get back computer objects.  A "user" is an account that accesses domain resources.  TO get only people type accounts we have to ad "objectcategory=person".  Get-AdUser does all of this by default.  What you will have to filter out are template accounts and service accounts.

February 20th, 2015 11:17pm

Can you tell us more about the computer accounts returned by Get-ADUser? Do they have objectClass "Computer" (in addition to "User")? Do they have a sAMAccountName that ends with the "$" character? Do they have objectCategory "Computer"?

I have never seen computer objects returned by Get-ADUser.

Free Windows Admin Tool Kit Click here and download it now
February 20th, 2015 11:23pm

I should add that Mike's snippet only works because the Get-ADUser cmdlet only returns the most specific value of the objectClass attribute. The actual AD objectClass attribute is multi-valued. Computer objects have both "computer" and "user" class. This is why jrv's filter is required.
February 20th, 2015 11:35pm

In a raw ADSI search it is "objectcategory" that differentiates.

([adsisearcher]'(&(objectclass=user)(objectcategory=person))').FindAll()

If we use only objectclass=user we will get back computer objects. A "user" is an account that accesses domain resources. TO get only people type accounts we have to ad "objectcategory=person". Get-AdUser does all of this by default. What you will have to filter out are template accounts and service acc

Free Windows Admin Tool Kit Click here and download it now
February 21st, 2015 12:18am

Actually, AD user objects have class: top, organizationPerson, person, and user. Computer objects have the same classes, plus computer. The result is that computers have the same attributes available as users, plus the extra ones inherited from the computer class. All AD objects have the top class.
February 21st, 2015 2:55am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics