-
Notifications
You must be signed in to change notification settings - Fork 0
/
Set-TrustAllCertsPolicy.ps1
32 lines (29 loc) · 1.07 KB
/
Set-TrustAllCertsPolicy.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<#
.SYNOPSIS
Set CertificatePolicy to trust all certs. This will remain in effect for this session.
.Functionality
Web
.NOTES
Not sure where this originated. A few references:
http://connect.microsoft.com/PowerShell/feedback/details/419466/new-webserviceproxy-needs-force-parameter-to-ignore-ssl-errors
http://stackoverflow.com/questions/11696944/powershell-v3-invoke-webrequest-https-error
#>
if([System.Net.ServicePointManager]::CertificatePolicy.ToString() -eq "TrustAllCertsPolicy")
{
Write-Verbose "Current policy is already set to TrustAllCertsPolicy"
}
else
{
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
}