运行驻留在远程计算机上的powershell脚本?
我们的服务器上有一个powershell脚本。正在尝试找出如何使用-ComputerName调用命令远程运行它,但在运行时:运行驻留在远程计算机上的powershell脚本?,powershell,Powershell,我们的服务器上有一个powershell脚本。正在尝试找出如何使用-ComputerName调用命令远程运行它,但在运行时: Invoke-Command - ComputerName XXXX -FilePath YYYY 似乎Invoke命令正在查找本地文件。如何指定要远程运行仅在远程计算机上可用的脚本?您可以使用-ScriptBlock参数 编辑:添加使用creds的版本 # Will bring up a dialogue box asking for credentials $cre
Invoke-Command - ComputerName XXXX -FilePath YYYY
似乎Invoke命令正在查找本地文件。如何指定要远程运行仅在远程计算机上可用的脚本?您可以使用
-ScriptBlock
参数
编辑:添加使用creds的版本
# Will bring up a dialogue box asking for credentials
$creds = get-credential
Invoke-Command -ComputerName machine1 -Credential $creds -Scriptblock {
. "C:\path\to\file.ps1"
}
你是说如果它在网络共享上?如果是这样,请在会话时尝试-authenization Credssp。这允许双跳如何添加用户名/密码凭据?
# Will bring up a dialogue box asking for credentials
$creds = get-credential
Invoke-Command -ComputerName machine1 -Credential $creds -Scriptblock {
. "C:\path\to\file.ps1"
}