PowerShell 7.3 - implementing Running a Remote Command and Capturing Output as Object
I've looked through the documentation and I'm still confused about I'm stuck on something that should probably be simple. I'm trying to execute a remote command on a Windows server using PowerShell 7.3, but I'm running into issues with capturing the output as a structured object. The command I'm trying to run is intended to retrieve some system information, specifically the OS version and the last boot time. Here's the code I've implemented: ```powershell $session = New-PSSession -ComputerName 'RemoteServer' -Credential (Get-Credential) $output = Invoke-Command -Session $session -ScriptBlock { Get-CimInstance -ClassName Win32_OperatingSystem | Select-Object Version, LastBootUpTime } Remove-PSSession -Session $session ``` When I execute this, I get the output, but it seems to be formatted as a plain string rather than an object. Hereโs the output I receive: ``` Version LastBootUpTime ------- ---------------- 10.0.19041 2023-10-01T10:15:00.0000000Z ``` I expect `$output` to hold an object that I could manipulate further, like this: ```powershell $output.Version ``` However, when I try to access properties, I encounter an behavior indicating that the object is not recognized. Iโve tried using `ConvertFrom-Json`, but that didnโt work as expected either. I've also ensured that the CIM cmdlet is available on the remote server. Is there something I'm missing in my command or the way I'm capturing the output? Any insights on how to properly retrieve and manipulate this data as an object would be greatly appreciated! My development environment is Linux. What's the best practice here? This is part of a larger web app I'm building. Any ideas what could be causing this?