I am new to Powershell and I am having trouble with the following. I need to run a Get-WmiObject command and get programs and versions. Here is the code:
Get-WmiObject -Class Win32_Product | where Name -eq "Microsoft Policy Platform" | select Name, Version >> c:\Temp\PRograms.txt ;
Get-WmiObject -Class Win32_Product | where Name -eq "Mitel Connect" | select Name, Version >> c:\Temp\PRograms.txt
I get this output:
Name Version
---- -------
Microsoft Policy Platform 68.1.1010.0
Name Version
---- -------
Mitel Connect 214.100.1252.0
What I am hoping to get is:
Name Version
---- -------
Microsoft Policy Platform 68.1.1010.0
Mitel Connect 214.100.1252.0
I have tried making it 1 line, separate commands, google and looking at like scripts with no luck. I am hoping someone can point me in the right direction so I can build on it.
CodePudding user response:
Just preform the WMI query once, and return both programs, and output them both to the text file at once.
Get-WmiObject -Class Win32_Product | where {$_.Name -in ("Microsoft Policy Platform", "Mitel Connect")} | Add-Content c:\Temp\Programs.txt
CodePudding user response:
Get-package would be much faster in this case, even than using -filter with wmi.
get-package 'Microsoft Policy Platform','Mitel Connect' |
select name,version | export-csv programs.csv