Solved

Powershell Exclude Wildcard

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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

The article will show you how you can maintain a simple logfile of all Startup and Shutdown events on Windows servers and desktops with PowerShell. The script can be easily adapted into doing more like gracefully silencing/updating your monitoring s…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

911 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

16 Experts available now in Live!

Get 1:1 Help Now