none
Filter Installed Program Script Qwuestion RRS feed

  • Question

  • Hi,

    Need some advise please as where I am going wrong with a script in powershell. I have a script I am developing that shows me the list of installed programs on a machine and then filter the results to show me only results from a vendor or containing a value.

    I have the first part of the script working where it brings up a list of the installed applications on my test machine.

    Get-WmiObject -Class Win32_Product -ComputerName . | Format-List -Property Name,Vendor,Version

    This brings up a very large list so I want to filter the results to just show my what version of flash is installed and this is where I am getting a bit stuck. I have tried... | where-Object -FilterScript {$_.Name -eq "flash"}

    Get-WmiObject -Class Win32_Product -ComputerName . | Format-List -Property Name,Vendor,Version | where-Object -FilterScript {$_.Name -eq "flash"}

    The script runs and comes back with no results and no errors, can anyone advise please?

    My aim to eventually use this script to query a load of remote computers to see what version of flash or java etc is installed as I have developed another script that updates our Citrix environment which works a treat but I need to know if they completed successfully hence why I am developing this script to show what apps are installed.

    Tuesday, June 12, 2018 12:27 PM

Answers

  • If you use "-eq" when filtering the Name would have to be exactly "flash". That's pretty unlikely. Instead you can use "-like" with some wildcards ... like this:

    Get-WmiObject -Class Win32_Product -ComputerName . | 
            Where-Object -FilterScript {$_.Name -like '*flash*'} | 
                Format-List -Property Name,Vendor,Version 

    ... and of course you have to filter before you format. Format cmdlets come always last in the pipeline.

    But actually you should stop by in the Microsoft Technet Script Library or in the Powershell Gallery. I'm pretty sure there a some scripts doing at least almost exactly what you're trying to create new  ..... ;-)  ... no need to re-invent the wheel.


    Best regards,

    (79,108,97,102|%{[char]$_})-join''



    • Edited by BOfH-666 Tuesday, June 12, 2018 1:08 PM
    • Marked as answer by ID-ten-T Tuesday, June 12, 2018 1:51 PM
    Tuesday, June 12, 2018 1:07 PM

All replies

  • If you use "-eq" when filtering the Name would have to be exactly "flash". That's pretty unlikely. Instead you can use "-like" with some wildcards ... like this:

    Get-WmiObject -Class Win32_Product -ComputerName . | 
            Where-Object -FilterScript {$_.Name -like '*flash*'} | 
                Format-List -Property Name,Vendor,Version 

    ... and of course you have to filter before you format. Format cmdlets come always last in the pipeline.

    But actually you should stop by in the Microsoft Technet Script Library or in the Powershell Gallery. I'm pretty sure there a some scripts doing at least almost exactly what you're trying to create new  ..... ;-)  ... no need to re-invent the wheel.


    Best regards,

    (79,108,97,102|%{[char]$_})-join''



    • Edited by BOfH-666 Tuesday, June 12, 2018 1:08 PM
    • Marked as answer by ID-ten-T Tuesday, June 12, 2018 1:51 PM
    Tuesday, June 12, 2018 1:07 PM
  • Hi,

    You need to change the order of format-list and where-object. And I'd suggest to use -like instead of -eq to search for "flash".

    Get-WmiObject -Class Win32_Product | where-Object {$_.Name -like "*flash*"} | Format-List -Property Name,Vendor,Version

    Tuesday, June 12, 2018 1:07 PM
  • The wild card has done the trick and changing the commands to use the filter first as you said. make sense now.

    Thanks you.

    Tuesday, June 12, 2018 2:22 PM