Matching Items

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 8 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
User avatar
localpct
Posts: 397
Last visit: Thu Oct 27, 2022 5:57 am

Re: Matching Items

Post by localpct »

I don't know how to use the -notmatch filter against a list of files using a txt file or CSV file

I don't know how to make the question and simpler

Let say a computer has
Adobe Reader and Adobe Photoshop installed. As in my OP, the .Log files in the picture show EVERY application installed. Using the -notmatch I can filter standard applications, so in this case, Reader is part of the list so it will only display Adobe Photoshop in the DGV.

If you would have really looked at my code, you would have noticed I'm NOT matching them. I can only assume that based on your statement of "I can only see your listing a bunch of files and matching them to a bunch of strings", that is incorrect as I'm doing the opposite. I've stated that in almost every reply.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Matching Items

Post by jvierra »

"notmatch" is a way of matching. It uses RegEx. As written I don't see what your code is trying to do. You cannot use this method to match a list from a file. "match/notmatch" does not work against an array.

If you use "notin" then all items in your array must be exact file names. If you want file names with ou the extension use "basename".
User avatar
localpct
Posts: 397
Last visit: Thu Oct 27, 2022 5:57 am

Re: Matching Items

Post by localpct »

Remember as a stated every computer has Adobe Reader, Flash, IBM Notes, Outlook etc..??
The folder I'm searching on stores the all install logs of a remote computer

As you can see in this screen shot, it's only showing those items that are not standard on every PC. I need to take that list and put it in a text file. If this can't be done, fine but I'm not sure how else I can explain it.
Attachments
sendout.png
sendout.png (24.7 KiB) Viewed 3411 times
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Matching Items

Post by jvierra »

By "put" are you asking how to export a control to a file? This is not at all like anything you described earlier.
User avatar
localpct
Posts: 397
Last visit: Thu Oct 27, 2022 5:57 am

Re: Matching Items

Post by localpct »

jvierra wrote: Mon Jul 31, 2017 9:24 pm "notmatch" is a way of matching. It uses RegEx. As written I don't see what your code is trying to do. You cannot use this method to match a list from a file. "match/notmatch" does not work against an array.

If you use "notin" then all items in your array must be exact file names. If you want file names with ou the extension use "basename".
So I have it matching with a text file and using this as an example for some applications

Code: Select all

$files = Get-Content C:\users\ME\Desktop\testnotmatch.txt

Get-ChildItem '\\remotePC\c$\windows\Logs' | Select-Object Name | where { $_.Name -notin $Files}
In the text file I have

Windows 7 Security Template1.1_vendor.Log
vSphere4.1_vendor.LOG
vSphere5.0_vendor.LOG

It's just too bad, I can't use this script and the external .txt file and have just _vendor to exclude all of the .Log files that have the name _vendor or _uninstall or Adobe Flash Player \d, etc...

:(
User avatar
localpct
Posts: 397
Last visit: Thu Oct 27, 2022 5:57 am

Re: Matching Items

Post by localpct »

Digging in this more. This is working.

Code: Select all

$NonStandardApps = Get-Content C:\users\me\Desktop\testnotmatch.txt
$COMPUTERS = GET-CONTENT C:\users\me\Desktop\HomeOffice.txt
$results = foreach ($computer in $COMPUTERS){
Get-ChildItem \\$computer\c$\windows\Logs -Exclude $nonstandardapps | Where {($_.PSIsContainer -eq $false)} | Select-Object Name, FullName
}
It was also pulling directories, so I add to add in the | Where {($_.PSIsContainer -eq $false)}
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Matching Items

Post by jvierra »

Get-ChildItem [[-File|-Directory]]
User avatar
localpct
Posts: 397
Last visit: Thu Oct 27, 2022 5:57 am

Re: Matching Items

Post by localpct »

jvierra wrote: Wed Aug 02, 2017 10:11 am Get-ChildItem [[-File|-Directory]]

??? not clear. If I do

Get-ChildItem \\remotePC\c$\windows\Logs -Exclude $nonstandardapps -file | Select-Object Name, FullName

ISE returns nothing. If I swap it to -Directory, it only list the one directory.

I'm completely fine with leaving it as it is.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Matching Items

Post by jvierra »

Code: Select all

Get-ChildItem \\remotePC\c$\windows\Logs\* -Exclude $nonstandardapps -file | 
      Select-Object Name, FullName
You need to use the wildcard.
User avatar
localpct
Posts: 397
Last visit: Thu Oct 27, 2022 5:57 am

Re: Matching Items

Post by localpct »

So I found a PC that has 1 file to return ( this is repeatable on different PCs of different model types ). The DGV just repeats itself and the progress bar does not move past 0
Attachments
get-apps.png
get-apps.png (28.07 KiB) Viewed 3348 times
This topic is 6 years and 8 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