我有一个脚本将另一个脚本复制到远程服务器然后执行第二个脚本。这上周工作正常,但今天第一个脚本的执行失败,说无法找到第二个脚本。作为故障排除的一部分,我在本地服务器上创建了第二个脚本的简单版本(仅包含写入主机“错误的服务器!”)。现在,当我运行第一个脚本时,虚拟第二个脚本在本地服务器上执行!
我已经通过下面的测试工具脚本粘贴了:
$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,则会话的计算机名称正确指向第二个服务器。
有什么想法吗?
答案 0 :(得分:1)
-FilePath
Invoke-Command
参数指定了脚本的本地路径 - 而不是目标计算机上的路径。 Invoke-Command
将负责将本地脚本文件转移到目标计算机,以便它可以在那里执行。