Go Premium for a chance to win a PS4. Enter to Win


powershell finding two spaces in displayname

Posted on 2013-11-18
Medium Priority
Last Modified: 2013-11-27
I am trying to get users who have more than one space between they're first and last name and having trouble. Her is what I have below.

get-qaduser -searchroot "contoso.local/users | where {$_.displayname -match "  "}
Question by:techdrive
  • 2
LVL 44

Accepted Solution

Vasil Michev (MVP) earned 2000 total points
ID: 39657577
Use this for instead:

where {$_.Displayname -match "\s{2,}"}

Open in new window

This will match any 2 or more occurrences of any whitespace char.
LVL 71

Expert Comment

ID: 39657920
Your original try should work, if the whitespace is really only space (ASCII 32). Probably there is a different "whitespace" character included in your display names, like a tab. The \s match will detect that, but I would prefer (just matter of taste, though):
get-qaduser -searchroot "contoso.local/users | where {$_.displayname -match '\s\s+'}

Open in new window


Expert Comment

ID: 39660662
I think you could get away with LIKE instead of Match, if you used a wildcard

get-qaduser -searchroot "contoso.local/users | where {$_.displayname -like "*  *"} 

Open in new window

LVL 71

Expert Comment

ID: 39660867
-like would do if there are only spaces, but then the original match would work.

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here in this article, you will get a step by step guidance on how to restore an Exchange database to a recovery database. Get a brief on Recovery Database and how it can be used to restore Exchange database in this section!
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
To show how to generate a certificate request in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.:  First we need to log into the Exchange Admin Center. Navigate to the Servers >> Certificates…
This video demonstrates how to sync Microsoft Exchange Public Folders with smartphones using CodeTwo Exchange Sync and Exchange ActiveSync. To learn more about CodeTwo Exchange Sync and download the free trial, go to: http://www.codetwo.com/excha…

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question