当前的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"