Solved

powershell finding two spaces in displayname

Posted on 2013-11-18
5
281 Views
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 "  "}
0
Comment
Question by:techdrive
  • 2
5 Comments
 
LVL 38

Accepted Solution

by:
Vasil Michev (MVP) earned 500 total points
Comment Utility
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.
0
 
LVL 68

Expert Comment

by:Qlemo
Comment Utility
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

0
 
LVL 7

Expert Comment

by:BT15
Comment Utility
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

0
 
LVL 68

Expert Comment

by:Qlemo
Comment Utility
-like would do if there are only spaces, but then the original match would work.
0

Featured Post

Integrate social media with email signatures

Is your company active on social media? Do you also use email signatures? Including social media icons in your email signature is a great way to get fans for free. Let all your email users know you’re on social media quickly and easily, in a single click.

Join & Write a Comment

Local Continuous Replication is a cost effective and quick way of backing up Exchange server data. The following article describes the steps required to configure Local Continuous Replication. Also, the article tells you how to restore from a backup…
Following basic email etiquette rules will help you write a professional email and achieve a good, lasting impression with your contacts.
In this video we show how to create a User Mailbox 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 Recipients >> Mailb…
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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now