0

I'm trying to get the OS version of a selection of the computers on my domain. I created a powershell command that does this but it is missing the computer name on the output.

This is the command
Get-ADComputer -Filter {name -Like "test"} | select "name" | foreach {$_.name} {Get-WmiObject -Class Win32_OperatingSystem -ComputerName $_.name} | Select-Object Description, Caption,SevicePackMajorVersion | out-gridview

I've tried adding addtional select-objects but they are all blank. I'm thinking this is because this wmiobject simply doesn't contain the machine name.

So my question is, as I'm piping in the name with $_.name is it possible it can be part of the output as well. I've tried using variations of ($_.name) in the select-object command but to no avail.

1 Answer 1

1

When you are using Get-WmiObject -Class Win32_OperatingSystem you can see the full list of properties available with the command Get-WmiObject -Class Win32_OperatingSystem | select-object *. Doing that would give you a table of properties and values. The property that would probably be helpful to you is the PSComputerName property.

So something like this should include the details you want.

Get-WmiObject -Class Win32_OperatingSystem -ComputerName . | select-object PSComputerName,Description,Caption,SevicePackMajorVersion 
1
  • Wow that simple thank you very much. I also didn't realise you could use select-object * that would have been handy to know in the past. Commented Aug 24, 2015 at 16:01

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.