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.
When you are using
Get-WmiObject -Class Win32_OperatingSystem
you can see the full list of properties available with the commandGet-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 thePSComputerName
property.So something like this should include the details you want.