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.

2 Answers 2


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? Commented Mar 16, 2013 at 10:11
  • Whoops wrote the wrong condition. Good catch.
    – HostBits
    Commented Mar 16, 2013 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
    Commented Mar 18, 2013 at 13:49
  • Is the above command the correct one? Did you edit it from your original post?
    – Perry
    Commented Mar 18, 2013 at 14:46
  • Updated the answer.
    – HostBits
    Commented Mar 18, 2013 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
    Commented Mar 18, 2013 at 13:53
  • Just updated it, try above Commented Mar 18, 2013 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
    Commented Mar 18, 2013 at 14:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .