Solved

Powershell Exclude Wildcard

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

Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

Question has a verified solution.

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

This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
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…

679 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