Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
运行驻留在远程计算机上的powershell脚本?_Powershell - Fatal编程技术网

运行驻留在远程计算机上的powershell脚本?

运行驻留在远程计算机上的powershell脚本?,powershell,Powershell,我们的服务器上有一个powershell脚本。正在尝试找出如何使用-ComputerName调用命令远程运行它,但在运行时: Invoke-Command - ComputerName XXXX -FilePath YYYY 似乎Invoke命令正在查找本地文件。如何指定要远程运行仅在远程计算机上可用的脚本?您可以使用-ScriptBlock参数 编辑:添加使用creds的版本 # Will bring up a dialogue box asking for credentials $cre

我们的服务器上有一个powershell脚本。正在尝试找出如何使用-ComputerName调用命令远程运行它,但在运行时:

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"
}