Can I add a column where I can show the operating system and the PS version?

Viewed 28

I want to display the operating system with the info of the PowerShell version, but I don't know how to do it.

Invoke-Command -ComputerName $wks -Credential $cred -Scriptblock {$PSVersionTable.PSVersion} -ErrorAction SilentlyContinue
Invoke-Command -ComputerName $wks -Credential $cred -Scriptblock {$PSVersionTable.PSVersion} -ErrorAction SilentlyContinue
2 Answers

Assuming these are all Windows targets, you can query the Win32_OperatingSystem WMI class for operating system details:

Invoke-Command -ComputerName $wks -Credential $cred -Scriptblock {
    $OSDetails = Get-WmiObject Win32_OperatingSystem
    [pscustomobject]@{
        PSVersion = $PSVersionTable.PSVersion
        OperatingSystem = $OSDetails.Caption
        OperatingSystemVersion = $OSDetails.Caption
    }
} -ErrorAction SilentlyContinue

You can also get the OS version from System.Environment:

Invoke-Command -ComputerName $wks -Credential $cred -Scriptblock {
  [PSCustomObject]@{
      PSVersion = $PSVersionTable.PSVersion
      OSVersion = ([System.Environment]::OSVersion).Version.ToString()
  }
} -ErrorAction SilentlyContinue
Related