Solved

Powershell Exclude Wildcard

Posted on 2015-01-23
2
187 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
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 39

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

Does Powershell have you tied up in knots?

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

In this previous article (https://oddytee.wordpress.com/2016/05/05/provision-new-office-365-user-and-mailbox-from-exchange-hybrid-via-powershell/), we made basic license assignments to users in O365. When I say basic, the method is the simplest way …
Synchronize a new Active Directory domain with an existing Office 365 tenant
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

810 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