Page 1 of 1

Select-Object -last 1?

Posted: Mon Feb 12, 2018 2:10 pm
by MarvelManiac
Hello,

So I gather applications off of a PC
Our log files tell us what applications have been installed.

I could pull the registry but I've found looking for the .log files to be much quicker

I have a problem where we have mutliple versions of applications
Chrome
Acrobat
Visio
etc..

If my list looks like this
Adobe Acrobat Pro DC 15
Adobe Acrobat Pro DC 17
Google Chrome 50.0.2661.94
Google Chrome 59.0
Microsoft Visio Pro for Office 365 1512 15.0.4779.1002
Microsoft Visio Pro for Office 365 1609 16.0.7369.2127

How would I get it to look like this
Adobe Acrobat Pro DC 17
Google Chrome 59.0
Microsoft Visio Pro for Office 365 1609 16.0.7369.2127

I only want to display the newest if there are more than one that eqaul

Re: Select-Object -last 1?

Posted: Tue Feb 13, 2018 1:54 am
by jvierra
There are no duplicates so how will you know which ones to compare?

Re: Select-Object -last 1?

Posted: Tue Feb 13, 2018 5:46 am
by skalizar
This should work in most cases, it assumes the application name is the start of the string and contains no digits and the version is at the end of the string and contains only digits and periods. Create an object with the original name, the application name and the version, using this regex.

https://regex101.com/r/7w6Jhy/1

Your object will look something like this.

Code: Select all

App                                                      AppName                          Version
Adobe Acrobat Pro DC 15                                  Adobe Acrobat Pro DC             15
...
Microsoft Visio Pro for Office 365 1609 16.0.7369.2127   Microsoft Visio Pro for Office   16.0.7369.2127
Then you can group on AppName and select the latest version. There maybe some versions that don't sort properly, like going from 9.1.0 to 10.1.1, but this is about as close as you will get unless you can pull a numeric version number from your source.

Re: Select-Object -last 1?

Posted: Tue Feb 13, 2018 9:45 am
by MarvelManiac
I’ll post my psf later. Maybe it’ll help show

I should have done it in the first place

Re: Select-Object -last 1?

Posted: Wed Feb 14, 2018 7:17 am
by MarvelManiac
Sorry for the delay. Here is my working example with lots of corporate applications removed from the excluded applications.txt but I think you'll get the jist

You'll only need to edit lines 206, 207 to get this to work
TestMatch.zip
(104.43 KiB) Downloaded 154 times