何时使用-Co​​mputerName和-ConnectionUri?

时间:2016-06-09 01:50:10

标签: powershell powershell-remoting

在我学习PowerShell的过程中,我偶然发现了令我困惑的事情。 我真的不明白为什么有时候我必须使用

New-PSSession -ComputerName "servername" 

而有时候

New-PSSession -ConnectionUri "http://FQDN/powershell" etc...

我无法找到这两种方法的明确解释。究竟有什么区别?

1 个答案:

答案 0 :(得分:2)

New-PSSession正在使用PSremoting,应在使用前进行配置。配置意味着您可以为每台计算机略微区别。最简单的示例是不同的端口和不同的端点名称。 Uri格式如下:<Transport>://<ComputerName>:<Port>/<ApplicationName>

对于默认配置,您只需要传递ComputerName,并且将对所有其他值采用默认值。

但是,如果您有非默认配置,则可以选择:

  • 传递ConnectionURI所有数据
  • 使用ComputerName以及UseSSLPortApplicationName参数来指定ConnectionURI值。

所以它只有两种方法可以将相同的信息传递给命令。

在您的示例中,您可以这样做:

New-PSSession -ConnectionUri "http://FQDN/powershell"

New-PSSession -ComputerName "FQDN" -UseSSl $false -ApplicationName "powershell"

两者的行为完全相同

相关问题