【问题标题】:Powershell will not allow ServerCertificateValidationCallback changePowershell 将不允许 ServerCertificateValidationCallback 更改
【发布时间】:2015-09-25 03:02:52
【问题描述】:

我正在尝试使用 Invoke-RestMethod 进行呼叫,但我要连接的服务器具有自签名证书。

经过一番搜索,我发现我需要运行以下命令才能使其工作:

[System.Net.ServicePointManager]::ServerCertificateValidationCallback = ${true}

几天前我这样做了,然后我的 Invoke-RestMethod 调用开始工作了。

然后我重新启动了我的服务器并尝试再次执行相同的操作,但现在我收到以下错误:

PS C:\Users\Administrator> [System.Net.ServicePointManager]::ServerCertificateValidationCallback = $True 异常设置“ServerCertificateValidationCallback”:“无法将值“True”转换为类型 “System.Net.Security.RemoteCertificateValidationCallback”。错误:“从 'System.Boolean' 到的无效转换 'System.Net.Security.RemoteCertificateValidationCallback'。"" 在行:1 字符:1 + [System.Net.ServicePointManager]::ServerCertificateValidationCallback = $True + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], SetValueInvocationException +fullyQualifiedErrorId : ExceptionWhenSetting 块引用

我尝试将我的执行策略设置为无限制,但我仍然遇到同样的问题。

我在 Windows Server 2012 上运行 PSVersion 3.0。

我不知道为什么它以前有效。我很确定我以前没有做过什么特别的事情。

如果有任何建议,我将不胜感激!

【问题讨论】:

    标签: powershell


    【解决方案1】:

    我终于找到了一个有以下命令的网站:

    [Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
    

    请注意“系统”。不见了。

    运行此命令按预期工作。

    【讨论】:

    • 正确命令:[Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
    • @Der_Meister 这似乎与我的答案相同。
    • 不,美元符号在您的答案中位于错误的位置。
    猜你喜欢
    • 1970-01-01
    • 2013-08-06
    • 2019-04-30
    • 1970-01-01
    • 1970-01-01
    • 2018-03-27
    • 2012-03-23
    • 1970-01-01
    • 2019-04-18
    相关资源
    最近更新 更多