0

我有一个脚本,它将另一个脚本复制到远程服务器,然后执行第二个脚本。上周工作正常,但今天第一个脚本的执行失败,说找不到第二个脚本。作为故障排除的一部分,我在本地服务器上创建了第二个脚本的简单版本(仅包含 Write-Host "Wrong Server!)。现在,当我运行第一个脚本时,虚拟的第二个脚本在本地服务器上执行!

我已经粘贴了下面的测试工具脚本:

$DeploymentFolderOnTargetServer = "c:\biztalkdeployment"

$TargetServer = "d-vasbiz01"                
$Username = "TFS_Service"
$Password = "x"
$SecPass = ConvertTo-SecureString $Password -AsPlainText -Force
$Cred = New-Object -typename System.Management.Automation.PSCredential -argumentlist $Username,$SecPass
$Session = New-PSSession -ComputerName $TargetServer -Authentication CredSSP -Credential $Cred
$Environment = "Dev"
$ExecuteScriptFilePath = join-path "$DeploymentFolderOnTargetServer" "ExecuteBizTalkAppMSI.ps1"
$MSI = "bin\debug\x.int.mis-3.0.0.msi"
$InstallFolderOnTargetServer = "C:\Program Files (x86)\x.Int.MIS for BizTalk 2010\3.0"

Write-Host "Session = $Session"
Write-Host "ExecuteScriptFilePath = $ExecuteScriptFilePath"
Write-Host "MSI = $MSI"
Write-Host "InstallFolderOnTargetServer = $InstallFolderOnTargetServer"
Write-Host "Environment = $Environment"
Write-Host "DeploymentFolderOnTargetServer = $DeploymentFolderOnTargetServer"


Invoke-Command -Session $Session  -FilePath $ExecuteScriptFilePath -argumentlist $MSI, $InstallFolderOnTargetServer, $Environment, $DeploymentFolderOnTargetServer             

测试的输出如下:

Session = System.Management.Automation.Runspaces.PSSession
ExecuteScriptFilePath = c:\biztalkdeployment\ExecuteBizTalkAppMSI.ps1
MSI = bin\debug\x.int.mis-3.0.0.msi
InstallFolderOnTargetServer = C:\Program Files (x86)\Vasanta.Int.MIS for BizTalk 2010\3.0
Environment = Dev
DeploymentFolderOnTargetServer = c:\biztalkdeployment
Wrong Server!

如果我运行 get-session 那么会话的计算机名正确地指向第二台服务器。

有任何想法吗?

4

1 回答 1

1

-FilePath参数 toInvoke-Command指定脚本的本地路径- 而不是目标计算机上的路径。Invoke-Command将负责将本地脚本文件转移到目标计算机,以便它可以在那里执行。

于 2012-08-07T15:37:37.833 回答