Solved

Powershell Exclude Wildcard

Posted on 2015-01-23
2
207 Views
Last Modified: 2015-01-23
I can exclude a name like "Random1" and "Random22", but if I wanted to exclude all names that started with "Random", is there a way to exclude with a wildcard? Random* does not seem to be working.

Here is the line I am starting with:

Get-ADPrincipalGroupMembership <user> | Select -Expand Name | Foreach-Object {$_.trim()} | Where-Object { 'Random*' -notcontains $_ }
0
Comment
Question by:stakor
[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 Comments
 

Accepted Solution

by:
stakor earned 0 total points
ID: 40566356
Does seem to work.

Get-ADPrincipalGroupMembership <user> | Select -Expand Name | Foreach-Object {$_.trim()} | Select-String 'Random' -NotMatch -SimpleMatch
0
 
LVL 40

Expert Comment

by:footech
ID: 40566704
The typical way to do this is is with Where-Object.
Get-ADPrincipalGroupMembership <user> | Select -Expand Name | Foreach-Object {$_.trim()} | Where-Object { $_ -notlike "Random*" }

Open in new window

You could also use the -notmatch operator instead of -notlike if you wanted to do RegEx matching.
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

Synchronize a new Active Directory domain with an existing Office 365 tenant
A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

615 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