Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/36.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_Powershell 2.0_Powershell Remoting - Fatal编程技术网

在powershell中运行远程脚本

在powershell中运行远程脚本,powershell,powershell-2.0,powershell-remoting,Powershell,Powershell 2.0,Powershell Remoting,我已经成功地让winrm工作,并且我能够在shell中运行Enter PSSession my machine,然后输入命令。但是,当我尝试运行启动远程会话的脚本时,所有后续调用都在本地计算机上运行。例如: PS> test.ps1 test.ps1的内容 Enter-PSSession remote-pcname gc env:computername 打印出local pcname而不是remote pcname您知道脚本文件为什么不支持远程会话吗?它肯定是成功连接的,因为当脚本完

我已经成功地让winrm工作,并且我能够在shell中运行
Enter PSSession my machine
,然后输入命令。但是,当我尝试运行启动远程会话的脚本时,所有后续调用都在本地计算机上运行。例如:

PS> test.ps1
test.ps1的内容

Enter-PSSession remote-pcname
gc env:computername

打印出
local pcname
而不是
remote pcname
您知道脚本文件为什么不支持远程会话吗?它肯定是成功连接的,因为当脚本完成时,我将返回到远程机器的shell提示符。

简短的回答是:Enter PSSession用于交互式使用。如果要从脚本在远程系统上执行命令,请使用invoke命令

Technet论坛上的类似帖子如下:

简短的回答是:Enter PSSession用于交互式使用。如果要从脚本在远程系统上执行命令,请使用invoke命令

Technet论坛上的类似帖子如下:

对我来说,它的工作方式是有据可查的
进入PSSession
启动一个交互式会话,用于交互式使用


因此,要执行脚本,您可以使用
New-PSSession
创建会话,并使用您使用New-PSSession创建的远程会话调用命令。

对我来说,它可以按文档所述工作
进入PSSession
启动一个交互式会话,用于交互式使用


因此,要执行脚本,您可以使用
New PSSession
创建会话,并使用您使用New PSSession创建的远程会话调用命令。

+1您之前回答,但在编写时我发布它,即使+1您之前回答,但在编写时我发布它,即使