I need to dump out the executable versions of certain apps and browsers - output formatting dilemma help please RRS feed

  • Question

  • Hi,

    I have thrown this code together to output the versions of executables on a local machine ( I know I could use registry but I know of machines with multiple instances and some standalone exe's later on in the project ). 

    The output to the screen is fine and that's in the format I want to capture, but when I append the string that I want so I could email it or stuff it in a csv later it obviously outputs the headers repeatedly and line feeds. I know this will be simple to you guys so please show me where I need to bend the code to do what I want.



    $results= ''
    $filestocheck = "Chrome.exe","iexplore.exe","MicrosoftEdge.exe","Firefox.exe"
    $dirstocheck = "C:\Windows\SystemApps\","c:\Program Files (x86)\","c:\program files\"
    foreach ($dirtocheck in $dirstocheck)
    foreach ($filetocheck in $filestocheck)
    get-childitem -path $dirtocheck -filter $filetocheck -Recurse | %{$_.VersionInfo} |Select-Object @{N='MachineName';E={$env:COMPUTERNAME}},FileDescription, FileVersion, FileName  

    $results += get-childitem -path $dirtocheck -filter $filetocheck -Recurse | %{$_.VersionInfo} |Select-Object @{N='MachineName';E={$env:COMPUTERNAME}},FileDescription, FileVersion, FileName  |Out-String

    #Write-host -NoNewline "`rChecking for versions of $filetocheck in $dirtocheck"
    Write-Progress -Activity "$filetocheck in $dirtocheck"


    • Moved by Bill_Stewart Friday, March 15, 2019 6:07 PM This is not "fix/debug/rewrite my script for me" forum
    Thursday, January 17, 2019 8:18 AM

All replies

  • First fix your post and post the code formatted correctly and use the code posting tool provided.  As posted it is unreadable.


    Thursday, January 17, 2019 8:37 AM
  • This is how to enumerate multiple folders for multiple files:

    $files = 'Chrome.exe', 'iexplore.exe', 'MicrosoftEdge.exe', 'Firefox.exe' 
    $folders = 'C:\Windows\SystemApps\', 'c:\Program Files (x86)\', 'c:\program files\'
    Get-ChildItem -Path $folders -Include $files -Recurse |
        Select-Object @{ N = 'MachineName'; E = { $env:COMPUTERNAME } }, Fullname, FileDescription, FileVersion
    You have to use computed values for all of the version properties.  I didn't fix that.


    • Edited by jrv Thursday, January 17, 2019 8:47 AM
    Thursday, January 17, 2019 8:43 AM
  • Runs in less than 5 seconds on a very loaded laptop.

    PS C:\WINDOWS\system32> Get-ChildItem -Path $folders -Include $files -Recurse |
    >> Select-Object $properties
    MachineName FullName                                                                      FileDescription   FileVersion
    ----------- --------                                                                      ---------------   -----------
    ALPHA       C:\Windows\SystemApps\Microsoft.MicrosoftEdge_8wekyb3d8bbwe\MicrosoftEdge.exe Microsoft Edge    11.00.17763.253 (WinBuild.160101.0800)
    ALPHA       C:\Program Files (x86)\Internet Explorer\iexplore.exe                         Internet Explorer 11.00.17763.1 (WinBuild.160101.0800)
    ALPHA       C:\program files\internet explorer\iexplore.exe                               Internet Explorer 11.00.17763.1 (WinBuild.160101.0800)


    Thursday, January 17, 2019 8:56 AM
  • This doesn't appear to display the Description and Version data when I run it. Is it my version of powershell or am I doing something wrong ?

    PS C:\WINDOWS\system32> $PSVersionTable

    Name                           Value                                                                                                                                                          
    ----                           -----                                                                                                                                                          
    PSVersion                      5.1.18312.1001                                                                                                                                                 
    PSEdition                      Desktop                                                                                                                                                        
    PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                                                        
    BuildVersion                   10.0.18312.1001                                                                                                                                                
    CLRVersion                     4.0.30319.42000                                                                                                                                                
    WSManStackVersion              3.0                                                                                                                                                            
    PSRemotingProtocolVersion      2.3                                                                                                                                                            

    The original script I put on here shows the data but I can't see why yours doesn't for me. Would like to use your code if I may as its more streamlined too :-)


    Thursday, January 17, 2019 10:58 AM
  • Like I posted above.  Those are embedded in the "VersionInfo" structure and have to be dug out with a calculated property.  You used one calculated property now just add two more.


    Thursday, January 17, 2019 11:02 AM
  • $files = 'Chrome.exe', 'iexplore.exe', 'MicrosoftEdge.exe', 'Firefox.exe' 
    $folders = 'C:\Windows\SystemApps\', 'c:\Program Files (x86)\', 'c:\program files\'
    Get-ChildItem -Path $folders -Include $files -Recurse |
        Select-Object @{ N = 'MachineName'; E = { $env:COMPUTERNAME } },{%({$_.VersionInfo.fileversion})}, FullName,{% {$_.VersionInfo.productversion}}

    MachineName %({$_.VersionInfo.fileversion})         FullName                                                                      % {$_.VersionInfo.productversion}
    ----------- -------------------------------         --------                                                                      ---------------------------------
    DSKIRVIN01  11.00.18312.1001 (WinBuild.160101.0800) C:\Windows\SystemApps\Microsoft.MicrosoftEdge_8wekyb3d8bbwe\MicrosoftEdge.exe 11.00.18312.1001                 
    DSKIRVIN01  71.0.3578.98                            C:\Program Files (x86)\Google\Chrome\Application\chrome.exe                   71.0.3578.98                     
    DSKIRVIN01  72.0.3626.64                            C:\Program Files (x86)\Google\Chrome Beta\Application\chrome.exe              72.0.3626.64                     
    DSKIRVIN01  11.00.18312.1001 (WinBuild.160101.0800) C:\Program Files (x86)\Internet Explorer\iexplore.exe                         11.00.18312.1001                 
    DSKIRVIN01  11.00.18316.1000 (WinBuild.160101.0800) C:\program files\internet explorer\iexplore.exe                               11.00.18316.1000                 
    DSKIRVIN01  58.0.2                                  C:\program files\Mozilla Firefox\firefox.exe                                  58.0.2                           

    Problem is the header name is same format as query ,, is this right ,, sorry I am struggling to get this done and it should not take this long...


    Thursday, January 17, 2019 12:49 PM
  • That means you need to use a calculated property and not just some code you invented.

    Search for articles on what a calculated query is.


    Thursday, January 17, 2019 4:59 PM