1

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.

3
  • 2
    It’s outputting 2 separate tables because you’re writing two separate sets of results. If you want them in one table you’ll need to combine the results before you write them to the file. For example Get-WmiObject -Class Win32_Product | where Name -in @( “Microsoft Policy Platform", “Mitel Connect") | select Name, Version >> c:\Temp\PRograms.txt ; Commented Jul 19, 2022 at 17:03
  • 1
    As an aside: The CIM cmdlets (e.g., Get-CimInstance) superseded the WMI cmdlets (e.g., Get-WmiObject) in PowerShell v3 (released in September 2012). Therefore, the WMI cmdlets should be avoided, not least because PowerShell (Core) v6+, where all future effort will go, doesn't even have them anymore. Note that WMI still underlies the CIM cmdlets, however. For more information, see this answer. Commented Jul 19, 2022 at 22:24
  • Piggybacking off this so I dont have to make a new post. If I want to check for example 7-zip, but what is listed is 7-Zip 21.07 (x64), how do I only look up 7zip? I have looked for examples and tried trimming the code with no luck. If no one answers, I will create a new question. And thank you mlkemento Commented Jul 20, 2022 at 15:27

2 Answers 2

1

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
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.