如何检查powerCLI中TrustAllCertsPolicy的定义

时间:2018-11-13 08:22:56

标签: powercli

当前的powercli版本是6.0(正在升级),我正在使用下面的代码忽略/信任所有证书。在运行时,PS脚本抱怨'TrustAllCertsPolicy'已经存在,如果我不添加以下类型,则invoke-webrequest无法查询“ https:/// mob”

add-type @"
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class TrustAllCertsPolicy : ICertificatePolicy {
    public bool CheckValidationResult(
        ServicePoint srvPoint, X509Certificate certificate,
        WebRequest request, int certificateProblem) {
        return true;
    }
}
"@
[System.Net.ServicePointManager]::CertificatePolicy = New-Object 
TrustAllCertsPolicy

$result = Invoke-WebRequest -Uri "https://IpAddress/resource"

0 个答案:

没有答案