Invoke-RestMethod - Ignore Self Signed Certs
This will also work in later versions of powershell with invoke-restmethod/webrequest. It avoids the requirement for a runspace by implementing the handler as native .net:
if (-not("dummy" -as [type])) { add-type -TypeDefinition @"using System;using System.Net;using System.Net.Security;using System.Security.Cryptography.X509Certificates;public static class Dummy { public static bool ReturnTrue(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; } public static RemoteCertificateValidationCallback GetDelegate() { return new RemoteCertificateValidationCallback(Dummy.ReturnTrue); }}"@}[System.Net.ServicePointManager]::ServerCertificateValidationCallback = [dummy]::GetDelegate()
Hope this helps.
If after @x0n answer, you still have the problem, try add before Request/Rest this
[System.Net.ServicePointManager]::SecurityProtocol =[System.Net.SecurityProtocolType]::Tls12
Working script for me:
if (-not ([System.Management.Automation.PSTypeName]'ServerCertificateValidationCallback').Type){$certCallback = @" using System; using System.Net; using System.Net.Security; using System.Security.Cryptography.X509Certificates; public class ServerCertificateValidationCallback { public static void Ignore() { if(ServicePointManager.ServerCertificateValidationCallback ==null) { ServicePointManager.ServerCertificateValidationCallback += delegate ( Object obj, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors ) { return true; }; } } }"@ Add-Type $certCallback }[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12;[ServerCertificateValidationCallback]::Ignore()Invoke-WebRequest https://*YOUR URI*
i know this is old, but it still came up when i had this question with out actually checking. google first right?
Try this:
invoke-restMethod -SkipCertificateCheck -uri 'https://server:4443/login' -etc..etc..etc..
got it here via google: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-restmethod?view=powershell-6