I have this command set which i want to run to get all installed apps and their versions. The commands are saved to a file name psGetAppVersions.ps1:
Content of psGetAppVersions.ps1:
powershell Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser -Force
powershell -Command “gp HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | select DisplayName, DisplayVersion, Publisher | Format-Table -AutoSize | Out-String -Width 4096 > C:\temp\testOut.txt”
When i launch it via terminal, i get the proper output ~ 17KB in size.
powershell .\psGetAppVersions.ps1
First few lines of the correct output are:
DisplayName DisplayVersion Publisher
Windows Driver Package - Plantronics, Inc. (usbser.ntamd64) Ports (04/21/2009 5.1) 04/21/2009 5.1 Plantronics, Inc.
Windows Driver Package - Cambridge Silicon Radio (CSRBC) USB (10/26/2012 2.4.0.0) 10/26/2012 2.4.0.0 Cambridge Silicon Radio
However, when i tried subprocess or pipe or open or os.system in both Python or Perl and invoke the command, i get a totally different output, something like ~41KB in size:
The first few lines on this incorrect output are:
DisplayName DisplayVersion Publisher
Cisco Webex Meetings 40.2.8 Cisco Webex LLC
Carbon Black Sensor 6.2.2.90503 Carbon Black, Inc.
It seems, whenever you invoke Powershell through Python or another interpreter like Perl, calling whatever method they support for command line execution, you will get the wrong output. I am completely shocked such bad results can be the case, especially when we want to try to automate such task and to verify the correct apps and their versions. Please help suggest a solution for this critical issue. This was run on Python 3.7.3 on Windows 10 as well as Strawberry Perl 5.30.2.1
Thanks in advance!