Select-Object -last 1?

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 1 month 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
MarvelManiac
Posts: 63
Last visit: Thu Sep 13, 2018 3:40 pm

Select-Object -last 1?

Post 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
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Select-Object -last 1?

Post by jvierra »

There are no duplicates so how will you know which ones to compare?
User avatar
skalizar
Posts: 18
Last visit: Wed Nov 22, 2023 12:43 pm

Re: Select-Object -last 1?

Post 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.
User avatar
MarvelManiac
Posts: 63
Last visit: Thu Sep 13, 2018 3:40 pm

Re: Select-Object -last 1?

Post by MarvelManiac »

I’ll post my psf later. Maybe it’ll help show

I should have done it in the first place
User avatar
MarvelManiac
Posts: 63
Last visit: Thu Sep 13, 2018 3:40 pm

Re: Select-Object -last 1?

Post 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
This topic is 6 years and 1 month 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