Quantcast
Channel: Use -notlike to filter out multiple strings in PowerShell - Stack Overflow
Browsing all 10 articles
Browse latest View live

Answer by ernie for Use -notlike to filter out multiple strings in PowerShell

don't use -notLike, -notMatch with Regular-Expression works in one line: Get-MailBoxPermission -id newsletter | ? {$_.User -NotMatch "NT-AUTORIT.*|.*-Admins|.*Administrators|.*Manage.*"}

View Article



Answer by Gill for Use -notlike to filter out multiple strings in PowerShell

Scenario: List all computers beginning with XX1 but not names where 4th character is L or P Get-ADComputer -Filter {(name -like "XX1*")} | Select Name | Where {($_.name -notlike "XX1L*" -and $_.name...

View Article

Answer by Gavin Burke for Use -notlike to filter out multiple strings in...

Easiest way I find for multiple searches is to pipe them all (probably heavier CPU use) but for your example user: Get-EventLog -LogName Security | where {$_.UserName -notlike "*user1"} | where...

View Article

Answer by Josh for Use -notlike to filter out multiple strings in PowerShell

In order to support "matches any of ..." scenarios, I created a function that is pretty easy to read. My version has a lot more to it because its a PowerShell 2.0 cmdlet but the version I'm pasting...

View Article

Answer by Keith Hill for Use -notlike to filter out multiple strings in...

I think Peter has the right idea. I would use a regular expression for this along with the -notmatch operator. Get-EventLog Security | ?{$_.Username -notmatch '^user1$|^.*user$'}

View Article


Answer by Peter Seale for Use -notlike to filter out multiple strings in...

$listOfUsernames = @("user1", "user2", "etc", "and so on") Get-EventLog -LogName Security | where { $_.Username -notmatch ( '(' + [string]::Join(')|(', $listOfUsernames) + ')') } It's a little crazy...

View Article

Answer by slipsec for Use -notlike to filter out multiple strings in PowerShell

V2 at least contains the -username parameter that takes a string[], and supports globbing. V1 you want to expand your test like so: Get-EventLog Security | ?{$_.UserName -notlike "user1" -and...

View Article

Answer by x0n for Use -notlike to filter out multiple strings in PowerShell

Yep, but you have to put the array first in the expression: ... | where { @("user1","user2") -notlike $_.username } -Oisin

View Article


Use -notlike to filter out multiple strings in PowerShell

I'm trying to read the event log for a security audit for all users except two, but is it possible to do that with the -notlike operator? It's something like that: Get-EventLog -LogName Security |...

View Article


Answer by js2010 for Use -notlike to filter out multiple strings in PowerShell

Using select-string:Get-EventLog Security | where {$_.UserName | select-string -notmatch user1,user2}

View Article
Browsing all 10 articles
Browse latest View live




Latest Images