I need to list of all users in AD that do not have any entry in the NAME field (example: smith,jon)

So far I have something like below

Get-ADUser -filter {Name -eq " "} | FT SamAccountName

I know this fails because of the empty quotations.

Essentially I need a piece of code that "lists all users who have a blank name field"

If there is another way to do this via PowerShell, or if I am just slightly off track with trying the blank quotes, let me know.

Any help is appreciated.


There are a few ways to go about this:

Get-ADUser -LDAPFilter "(!GivenName=*)" | ft samAccountName

Get-ADUser -Filter * | Where {$_.GivenName -eq $Null -OR $_.Surname -eq $Null -OR $_.Name -eq $Null} | select samAccountName

That should work for you.

Added a second command that will check if any of the "name" fields are blank.

  • Isn't that the opposite of what he is asking? Mar 16 '13 at 10:11
  • Whoops wrote the wrong condition. Good catch.
    – HostBits
    Mar 16 '13 at 12:21
  • I need a command that outputs users where the NAME field (or any field, such as Surname or GivenName, etc), has no data filled in.
    – Perry
    Mar 18 '13 at 13:49
  • Is the above command the correct one? Did you edit it from your original post?
    – Perry
    Mar 18 '13 at 14:46
  • Updated the answer.
    – HostBits
    Mar 18 '13 at 14:50

If you want all users where the Name attribute is either NULL, empty or consisting only of whitespace you should be able to do so like this:

Get-ADUser -Filter * | where {[System.string]::IsNullOrEmpty(($_.Name).Trim())} | select sAMAccountName
  • I can't seem to get this command to work. Once I execute it, it prompts me to "Supply values for the following parameters : Filter". I try and supply a parameter and it fails
    – Perry
    Mar 18 '13 at 13:53
  • Just updated it, try above Mar 18 '13 at 13:54
  • So I ran what you gave me, and it returned no results (which may mean I have no users with blank NAME fields, good so far). I edited your code to change $_.Name to $_.GivenName and the code blew up. Can I not just do that?
    – Perry
    Mar 18 '13 at 14:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.