使用winrm执行/调用本地ps1文件

时间:2016-12-15 05:44:20

标签: powershell azure winrm winrs

我已经有好几天这个问题了。使用winrm完成并研究了与在本地计算机上执行powershell脚本有关的所有内容。

我的目标是从本地到目标远程计算机执行这些ps1脚本。 winrm已配置并使用其基本命令,但我找不到任何使用winrm运行powershell脚本(* .ps1)的内容。

类似

winrm {execute ps1 file} -r:http://<IPaddress>:5985 -auth:basic -u:'username' -p:'password' -encoding:utf-8

非常感谢任何帮助和建议。

谢谢你们!

1 个答案:

答案 0 :(得分:1)

首先 - 我相信您正在尝试使用winrs而非winrm - 后者通常用于配置winrm,以前用于运行远程命令。

考虑到这一假设:我非常确定您必须将脚本传递给powershell.exe并负责转义命令元素。对我有用的例子(不是基本的认证,但我认为无关紧要):

winrs -r:ComputerName powershell -file c:\temp\test.ps1
winrs -r:ComputerName powershell -file "c:\temp\test with space.ps1"

为什么有人想要这样做是我猜的不同。你被要求去的任何好理由: powershell - &gt;本机命令 - &gt;遥控器上的cmd.exe和 - &gt;远程调用PowerShell?

像你松散的那样做:

  • 任何合理的输出(你得到文字)
  • 在脚本运行后保持状态
  • 性能(每次调用时生成新的PowerShell实例

你获得:

  • 复杂性