Solved

powershell finding two spaces in displayname

Posted on 2013-11-18
5
285 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 40

Accepted Solution

by:
Vasil Michev (MVP) earned 500 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.
0
 
LVL 69

Expert Comment

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

0
 
LVL 7

Expert Comment

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

0
 
LVL 69

Expert Comment

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

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

Suggested Solutions

Title # Comments Views Activity
Python to .bat or Powershell 2 31
Exchange 2016 CU5 upgrade stuck 9 76
Powershell to Query Child Domains 4 13
Powershell- Registry HIVE 6 23
MS Outlook is a world-class email client application that is mainly used for e-communication globally.  In this article, we will discuss the basic idea about MS Outlook, its advanced features, and types of MS Outlook File formats.
How to resolve IMCEAEX NDRs in Exchange or Exchange Online related to invalid X500 addresses.
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
This video discusses moving either the default database or any database to a new volume.

733 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