Solved

Powershell Exclude Wildcard

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

How to sign a powershell script so you can prevent tampering, and only allow users to run authorised Powershell scripts
Synchronize a new Active Directory domain with an existing Office 365 tenant
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

743 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

12 Experts available now in Live!

Get 1:1 Help Now