Skip to content

Instantly share code, notes, and snippets.

@jborean93
Created July 1, 2025 21:40
Show Gist options
  • Save jborean93/683bfb575e45b649b5856d3651ef63ab to your computer and use it in GitHub Desktop.
Save jborean93/683bfb575e45b649b5856d3651ef63ab to your computer and use it in GitHub Desktop.
Various ways of ignoring self signed certificates in Windows PowerShell 5.1
# Copyright: (c) 2025, Jordan Borean (@jborean93) <[email protected]>
# MIT License (see LICENSE or https://opensource.org/licenses/MIT)
using namespace System.Net
using namespace System.Net.Security
Function Disable-CertificateTrust {
[CmdletBinding()]
param ()
Add-Type -TypeDefinition @'
using System;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
namespace PwshTrust
{
public static class CertCallback
{
public static bool IgnoreCert(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
return true;
}
}
}
'@
[ServicePointManager]::ServerCertificateValidationCallback = [Delegate]::CreateDelegate(
[RemoteCertificateValidationCallback],
[PwshTrust.CertCallback].GetMethod('IgnoreCert'))
}
# Copyright: (c) 2025, Jordan Borean (@jborean93) <[email protected]>
# MIT License (see LICENSE or https://opensource.org/licenses/MIT)
using namespace System.Linq.Expressions
using namespace System.Net
using namespace System.Net.Security
using namespace System.Security.Cryptography.X509Certificates
Function Disable-CertificateTrust {
[CmdletBinding()]
param ()
$callback = [Expression]::Lambda(
[RemoteCertificateValidationCallback],
[Expression]::Constant($true, [bool]),
[Expression]::Parameter([object], "sender"),
[Expression]::Parameter([X509Certificate], "certificate"),
[Expression]::Parameter([X509Chain], "chain"),
[Expression]::Parameter([SslPolicyErrors], "sslPolicyErrors")
).Compile()
[ServicePointManager]::ServerCertificateValidationCallback = $callback
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment