REST API using SHELL scripts without CURL

I currently use this snippet of code (with proprietary snippets missing) for a very large PShell script.

# Allow the use of self signed certificates and set TLS

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

#C# class to create callback

$code = @"

public class SSLHandler

{

public static System.Net.Security.RemoteCertificateValidationCallback GetSSLHandler()

{

return new System.Net.Security.RemoteCertificateValidationCallback((sender, certificate, chain, policyErrors) => { return true; });

}

}

"@

#compile the class

Add-Type -TypeDefinition $code

$AllCredential = Get-Credential -Message "Enter appropriate credentials for DSM."

#disable checks using new class

[System.Net.ServicePointManager]::ServerCertificateValidationCallback = [SSLHandler]::GetSSLHandler()

# Create a base64 encoding for HTTP authentication.

$bytes = [System.Text.Encoding]::UTF8.GetBytes(('{0}:{1}' -f $AllCredential.UserName, $AllCredential.GetNetworkCredential().Password))

# Create Header

$Authorization = 'Basic {0}' -f ([Convert]::ToBase64String($bytes))

$header = @{ Authorization = $Authorization }

Invoke-RestMethod -Uri $build_url -Headers $header -Method Get -ContentType 'application/json'

/r/linuxadmin Thread