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

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
  • 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. – Drifter104 Aug 24 '15 at 16:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.