2014-10-16 118 views
1

PsExec似乎從本地運行命令期望的返回不同類型。我試圖用這個PsExec返回數據類型

$computerSystem = &$workingDirectory/psexec.exe \\10.44.20.20 powershell.exe "Get-CimInstance CIM_ComputerSystem" 

常用的返回類型爲Get-CimInstance CIM_ComputerSystem回報CimInstance遠程Get-CimInstance CIM_ComputerSystem運行此命令和會員可以這樣$computerSystem.Name進行訪問。

但是,當使用psexec時,它會返回一個奇怪格式的Object Array。在調試時查看變量時,它看起來與CimInstance具有相同的成員,但由於對象數組類型而無法訪問它們。

有沒有辦法將它轉換爲CimInstance或獲取psexec來訪問其成員或使psexec返回預期類型?

+1

爲什麼使用'psexec'而不是PowerShell遠程('invoke-command')或將'-computername'傳遞給'get-ciminstance'? – alroc 2014-10-16 13:06:15

+0

我不知道Get-CimInstance的-ComputerName參數。這解決了我遇到的問題,謝謝。任何想法爲什麼PsExec這樣表現? – John 2014-10-16 13:14:51

+1

'psexec'不是PowerShell,不能返回對象。它只是像任何其他命令一樣輸出字符串,PowerShell隨後會解析這些字符串。就像@alroc說的那樣,你想使用有問題的命令的實際遠程功能。 ('PsExec'中的'ps'不代表PowerShell - [該前綴被採用,因爲用於列表進程的標準Unix命令是'ps'](http://technet.microsoft.com/zh-cn/ sysinternals/bb896649.aspx)。) – 2014-10-16 13:15:06

回答

2

使用-ComputerName參數爲Get-CimInstance而不是psexec。這將返回Powershell可用的對象,而不是字符串數據。