因此,我們在自動化中使用PsExec來安裝虛擬機,因爲我們無法在Windows 2003計算機上使用ps遠程會話。一切都很好,沒有任何問題,但是PsExec不斷拋出錯誤,即使每個命令都沒有正確執行。 例如:PsExec引發錯誤消息,但沒有任何問題
D:\tools\pstools\psexec.exe $guestIP -u $global:default_user -p $global:default_pwd -d -i C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -command "Enable-PSRemoting -Force"
啓用guest虛擬機上PsRemoting,但也會引發此錯誤消息:
psexec.exe :
Bei D:\Scripts\VMware\VMware_Module5.ps1:489 Zeichen:29
+ D:\tools\pstools\psexec.exe <<<< $guestIP -u $global:default_user -p $global:default_pwd -d -i C:\Windows\System32\WindowsPowerShell\
v1.0\powershell.exe -command "Enable-PSRemoting -Force"
+ CategoryInfo : NotSpecified: (:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
PsExec v1.98 - Execute processes remotely
Copyright (C) 2001-2010 Mark Russinovich
Sysinternals - www.sysinternals.com
Connecting to 172.17.23.95...Starting PsExec service on 172.17.23.95...Connecting with PsExec service on 172.17.23.95...Starting C:\Windows\
System32\WindowsPowerShell\v1.0\powershell.exe on 172.17.23.95...
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe started on 172.17.23.95 with process ID 2600.
這些類型的錯誤消息apear總是不管我如何使用PSEXEC,喜歡用引號,與Vriables /固定值,其他標誌等有沒有人有一個想法,我可以解決這個問題?這不是一個真正的問題,但它使得發現錯誤成爲屁股疼痛,因爲「錯誤」無處不在。禁用psexec的錯誤信息也會有所幫助...
我有同樣的問題,我用'$ ErrorActionPreference =「SilentlyContinue」'的PSEXEC命令。但這不是一個真正的解決方案。 – plunkets
好吧,不是最好的主意,但比我的「解決方案」更好。我猜,我會編寫一個psexec-silent函數,在psexec命令之前打開和關閉ErrorActionPreference。至少我可以關掉錯誤信息,這顯然不是一個。 – Simons0n
檢查此; http://stackoverflow.com/a/2095623/469777 –