2013-10-29 38 views
1

我試圖在另一臺計算機上遠程安裝PowerShell軟件(.exe)。我現在有:PowerShell調用 - 命令遠程使用共享

Invoke-Command -Authentication Credssp -Credential $cred -ComputerName "TargetComputer01" -ScriptBlock {Start-Process -FilePath $args[0] -ArgumentList ('/log "{0}" /quiet /norestart' -f $args[1]) -Wait -PassThru -Verb RunAs} -ArgumentList @($Installer, $LogPath) 

這是不行的,沒有錯誤,沒有日誌文件,無需安裝軟件。所以我不知道爲什麼它不起作用。我使用Credssp是因爲安裝程序位於共享上。當我某個地方安裝上TargetComputer01,它正在與一個會話,請參閱:

Invoke-Command -Session $session -ScriptBlock {Start-Process -FilePath $args[0] -ArgumentList ('/log "{0}" /quiet /norestart' -f $args[1]) -Wait -PassThru -Verb RunAs} -ArgumentList @($Installer, $LogPath) 

任何想法,爲什麼與CredSSP的第一個命令不工作?


是的我也用這些命令啓用了Credssp。看起來,我的腳本在TargetComputer01(Windows Server 2012)上成功運行,但未在TargetComputer02(Windows Server 2008 R2)上成功運行。 PowerShell版本相同,所有其他配置也相同(例如防火牆設置)。然而

我找到一種方式來獲得它PSSession的工作,請看下面的代碼:

$cred = Get-Credential -UserName "domain\username" -Message "Enter your credentials" 
$session = New-PSSession -ComputerName "TargetComputer02" -Credential $cred -Authentication Credssp 

Invoke-Command -Session $session -ScriptBlock { 
    param 
    (
     $Installer, $LogPath 
    ) 
    Start-Process -FilePath $Installer -ArgumentList ('/log "{0}" /quiet /norestart' -f $LogPath) -Wait -PassThru -Verb RunAs 
} -ArgumentList @($Installer, $LogPath) 

我不知道爲什麼其他調用命令沒有會話,但用的CredSSP不能在Windows工作Server 2008 R2,但上面的代碼適用於兩個操作系統! :)

+0

Credssp可能會有點讓人無法正常工作。你能解釋爲什麼你認爲你需要使用Credssp嗎?確保您的$ cred對象不爲null。 – tnw

+0

我更喜歡使用會話,但我認爲我必須使用Credssp,因爲我的.exe文件位於(DFS)共享上。當我使用第二個命令(使用會話)時,使用共享時會出現Access Denied錯誤。 – JustRonald

回答

1

你真的啓用CredSSP在兩臺電腦上?請參閱Enable-WSManCredSSP命令。

在客戶端計算機,或者你在運行該腳本的計算機,您需要將其設置爲委派憑據到目標計算機:

Enable-WSManCredSSP -role Client -DelegateComputer "TargetComputer01" 

您應該確認這是由去設置正確到gpedit.msc - >計算機配置 - >系統 - >憑據委派。 「委派新鮮資格證書」應已啓用,而當你打開細節吧,TargetComputer01應該出現類似「WSMAN/TargetComputer01」

現在接收計算機上:

Enable-WSManCredSSP -role Server 

也使確定你在TargetComputer01上運行Enable-PSRemoting

讓我知道這是否適合你!