Reputation: 1596
PsExec seems to be returning different types from what would be expected from running the command locally. I'm trying to run this command remotely Get-CimInstance CIM_ComputerSystem
using this
$computerSystem = &$workingDirectory/psexec.exe \\10.44.20.20 powershell.exe "Get-CimInstance CIM_ComputerSystem"
The usual return type for Get-CimInstance CIM_ComputerSystem
returns a CimInstance and members can be accessed like this $computerSystem.Name
.
However, when using psexec it returns a strangely formatted Object Array. When looking at the variable whilst debugging it appears to have the same members as the CimInstance but they can't be accessed due to the object array type.
Is there a way to cast this to a CimInstance or get psexec to access its members or to make psexec return the expected type?
Upvotes: 1
Views: 862
Reputation: 28194
Use the -ComputerName
parameter for Get-CimInstance
instead of psexec
. This will return objects which are usable by Powershell, instead of string data.
Upvotes: 2