Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 6 years and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
localpct
Posts: 397
Last visit: Thu Oct 27, 2022 5:57 am
Post
by localpct » Thu May 18, 2017 8:51 am
So I'm still working through an application to exclude apps (
viewtopic.php?f=18&t=11296&start=10 )
I'm having a problem that when my code reads
#$_.Name -notmatch "1E Agent", it includes an application called Autonomy Qfiniti 3.5 SP2U3
Any thoughts?
$script :files = Invoke- Command - ScriptBlock { Get-ChildItem \\$FQDN \C$\Windows\logs -File } |
Select-Object Name | where {
#region #
$_ .Name -notmatch "$($textbox1.Text)" -and
$_ .Name -notmatch ".dpx" -and
$_ .Name -notmatch ".LOG2" -and
$_ .Name -notmatch ".Net Data" -and
$_ .Name -notmatch ".Net Framework" -and
$_ .Name -notmatch ".txt" -and
$_ .Name -notmatch "_32bit" -and
$_ .Name -notmatch "_64bit" -and
$_ .Name -notmatch "_Installation" -and
$_ .Name -notmatch "_Installer" -and
$_ .Name -notmatch "_PoSh" -and
$_ .Name -notmatch "_SuccessCheck" -and
$_ .Name -notmatch "_Update" -and
#$_.Name -notmatch "E Agent" -and
$_ .Name -notmatch "810F.50" -and
$_ .Name -notmatch "9470" -and
$_ .Name -notmatch "6.1.0.373-x64" -and
$_ .Name -notmatch "6.1.0.373-x86"
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times
Post
by jvierra » Thu May 18, 2017 9:30 am
The correct way to do this is like this:
$_.Name -notmatch ($textbox1.Text + '|\.dpx|\.LOG2|\.Net Data ... etc ...')
All special characters must be escaped.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times
Post
by jvierra » Thu May 18, 2017 9:34 am
"match" any is OR and "match all" is AND.
localpct
Posts: 397
Last visit: Thu Oct 27, 2022 5:57 am
Post
by localpct » Thu May 18, 2017 12:25 pm
jvierra wrote: The correct way to do this is like this:
$_.Name -notmatch ($textbox1.Text + '|\.dpx|\.LOG2|\.Net Data ... etc ...')
All special characters must be escaped.
Maybe I'm missing something, but does it have to be written on one line?
I've tried
$_.Name -notmatch ($textbox1.Text + '|\.dpx
|\.LOG2|
\.Net Data')
and
$_.Name -notmatch ($textbox1.Text + '|\.dpx|
\.LOG2|
\.Net Data')
And it stops filtering
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times
Post
by jvierra » Thu May 18, 2017 12:29 pm
$_.Name -notmatch ($textbox1.Text + '|\.dpx|\.LOG2|\.Net Data')
You cannot have line breaks in regex.
localpct
Posts: 397
Last visit: Thu Oct 27, 2022 5:57 am
Post
by localpct » Thu May 18, 2017 1:02 pm
jvierra wrote: $_.Name -notmatch ($textbox1.Text + '|\.dpx|\.LOG2|\.Net Data')
You cannot have line breaks in regex.
Okay, I did all of that but now when I add Adobe Shockwave Player it removes Autonomy Qfiniti 3.5 SP2U3
Something in the line must be doubled, or maybe an additional space somewhere... Not really sure
This list has 411 applications to exclude
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times
Post
by jvierra » Thu May 18, 2017 1:13 pm
"match" will match any part of the name. You must test each pattern. Without the contents of the textbox it is hard to say. Nothing in Adobe matches the pattern.
Anything that does not match the patterns will be passed.
$_.Name -notmatch ($textbox1.Text + '|\.dpx|\.LOG2|\.Net Data|Qfiniti ')
PS> 'Autonomy Qfiniti 3.5 SP2U3' -match '\.dpx|\.LOG2|\.Net Data|Qfinity'
False
PS> 'Autonomy Qfiniti 3.5 SP2U3' -match '\.dpx|\.LOG2|\.Net Data|Qfiniti'
True
PS> 'Autonomy Qfiniti 3.5 SP2U3' -notmatch '\.dpx|\.LOG2|\.Net Data|Qfiniti'
False
PS> 'Autonomy Qfiniti 3.5 SP2U3' -notmatch '\.dpx|\.LOG2|\.Net Data'
True
PS>
You have to figure out which logic you want to use.
localpct
Posts: 397
Last visit: Thu Oct 27, 2022 5:57 am
Post
by localpct » Fri May 19, 2017 10:31 am
I need it to -notmatch against 400+ applications
But I re did my where {$_.Name } line and everything seems to be pulling correctly.
Thanks!
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times
Post
by jvierra » Fri May 19, 2017 10:41 am
Create an array of app names and use "-notin"
$appnames = Get-Content appnames.txt
$name -notin $appnames
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times
Post
by jvierra » Fri May 19, 2017 10:55 am
Here is a very efficient way to do this:
$apps = '.Net' , '.DOC' , 'Something'
#$apps = Get-Content appslist.txt
$nametocheck = 'Microsoft.Net'
$apps |
ForEach-Object -Begin { $found = $false } -Process {
if ( $found ) { break }
$found = if ( $nametocheck -match [ regex ] ::Escape( $_ ) ) { $true }
}
$found
#
This topic is 6 years and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked