小编Rob*_*rto的帖子

Powershell脚本在远程执行期间失败,但可以在本地运行

我正在尝试执行以下代码。这些错误是不言自明的,但仅在远程运行时发生。在本地运行时,所有代码都可以正常工作,我可以通过从需要Tls12的Web服务器中提取内容并在未更改安全协议的情况下收到错误来验证它们是否具有预期的效果。

$tls12 = [Enum]::ToObject([Net.SecurityProtocolType], 3072)
[Net.ServicePointManager]::SecurityProtocol = $tls12
Run Code Online (Sandbox Code Playgroud)

在服务器上运行时,它们可以完美执行。通过Invoke-Command远程运行时,出现此错误。

Exception setting "SecurityProtocol": "The requested security protocol
is  not supported."
+ CategoryInfo          : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyAssignmentException
+ PSComputerName        : servername
Run Code Online (Sandbox Code Playgroud)

或者,这行代码从根本上是相同的。

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Run Code Online (Sandbox Code Playgroud)

直接在服务器上运行时,此方法也有效,但在远程运行时,会导致此错误。

Exception setting "SecurityProtocol": "Cannot convert null to type
 "System.Net.SecurityProtocolType" due to invalid enumeration values. Specify one of the following enumeration values and 
try again. The possible enumeration values are "Ssl3, Tls"."
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : …
Run Code Online (Sandbox Code Playgroud)

powershell powershell-2.0 powershell-remoting

5
推荐指数
1
解决办法
2234
查看次数