2017-02-17 22 views
0

我想創建一個腳本,將採取輸入(現在的硬編碼值)和調用安裝PS腳本並在多個服務器上運行它。我正在使用PSSession和Invoke-Command(請參閱下文)。以下運行,但什麼都不做。它似乎沒有調用其他腳本。除了實際安裝之外,我需要知道它是否成功。我是Powershell的新手,所以任何提示/幫助/建議都會很棒。下面是包裹在foreach循環使用$計算機服務器調用另一個遠程腳本與多個參數不工作

 Try 
    { 
     $session = New-PSSession -ComputerName App02 -Credential $cred 

     $sourceInstall = $sourceFolder + 'Install\Install.ps1' 
     Invoke-Command -Session $session -ScriptBlock{param($serviceName, $installFolder, $sourceFolder, $Action, $username, $password) $sourceInstall} -ArgumentList ($ServiceName, $installFolder, $sourceFolder, $Action, $username, $password) 
    } 
Catch 
    { 
    $Filename = "Error.txt" 
     Write-Output "ERROR: Partial Service Deployment. See error log file(s)" 
     Add-Content $Filename $_.Exception.Message 
    } 
    Get-PSSession | Remove-PSSession 
+0

1)您不會將'$ sourceInstall'變量傳遞給遠程會話。 2)你的遠程命令只是返回遠程'$ sourceInstall'變量的值,但不執行它指向的腳本。 – PetSerAl

+0

@PetSerAl如何讓腳本運行呢?另外,如果我在install.ps1腳本中放入return語句,是否允許本地腳本知道錯誤消息? – Styxtb1598

+0

它取決於PowerShell版本。使用v3 +,您可以只使用&$ using:sourceInstall'。 – PetSerAl

回答

相關問題