Powershell 调用服务器脚本的调用命令错误
我在客户端计算机中有此脚本,尝试从服务器计算机运行脚本:Powershell 调用服务器脚本的调用命令错误,powershell,powershell-remoting,Powershell,Powershell Remoting,我在客户端计算机中有此脚本,尝试从服务器计算机运行脚本: try { $s = New-PSSession -ComputerName "name" -Authentication CredSSP -Credential $credential Enter-PSSession -Id $s.Id Set-ExecutionPolicy ByPass -Scope CurrentUser Invoke-Command -Session $s -Fil
try {
$s = New-PSSession -ComputerName "name" -Authentication CredSSP -Credential $credential
Enter-PSSession -Id $s.Id
Set-ExecutionPolicy ByPass -Scope CurrentUser
Invoke-Command -Session $s -FilePath c:\release1.ps1
} catch {
Write-Error "Error occurred: " $_.Exception.ToString()
} finally {
Exit-PSSession
Remove-PSSession $s }
服务器中的脚本如下所示
设置别名vmrun“C:\Program Files(x86)\VMware\VMware Workstation\vmrun.exe”
启动进程-nonewindow-FilePath vmrun-ArgumentList“-T ws revertToSnapshot M:\myvm.vmx Release1”
但是我弄错了
写入错误:找不到接受参数“System.Management.Automation.ItemNotFoundException:cannot”的位置参数
查找路径“C:\release1.ps1”,因为它不存在
-FilePath
必须指定本地计算机上文件的路径。文件在本地读取,然后作为代码块传递到远程计算机
见:
在一台或多台远程计算机上运行指定的本地脚本。输入脚本的路径和文件名,或通过管道传输脚本路径以调用命令脚本必须位于本地计算机或本地计算机可以访问的目录中。使用ArgumentList参数指定脚本中的参数值
解决方案是将release1.ps1
放在本地计算机上。或者,如果必须在远程计算机上,则将其放入本地计算机可以访问的共享中,并使用UNC路径访问它
Invoke-Command -Session $s -FilePath \\name\share\release1.ps1
-FilePath
必须指定本地计算机上文件的路径。C:\release1.ps1
在本地计算机上还是远程计算机上?文件在远程计算机上