Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
#Disable SSL Cert Check
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 +=
Object obj,
X509Certificate certificate,
X509Chain chain,
SslPolicyErrors errors
return true;
Add-Type $certCallback
#Device Variables
$uri =""
$username = "deviceusername"
$password = "devicepassword"
$configname = "$(get-date -f yyyy-MM-dd).xml"
#API Key Function
function generate_pa_api_key {
$keygen = Invoke-WebRequest -Uri $uri/?type=keygen"&"user=$username"&"password=$password
$xml = [xml]$keygen.content
$key = $xml.response.innertext
return $key
#Generate Key
Write-Host "Generating PA API Key"
$devicekey = generate_pa_api_key
write-host "API Key: $devicekey"
#Backup config
write-host "Backing up config from $uri"
$urlstring = $uri + '?type=export&category=configuration&key='+$devicekey
$configrequest = Invoke-WebRequest -Uri $urlstring
$config = [xml]$configrequest.Content
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.