Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
backup_pa_config.ps1
#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 +=
delegate
(
Object obj,
X509Certificate certificate,
X509Chain chain,
SslPolicyErrors errors
)
{
return true;
};
}
}
}
"@
Add-Type $certCallback
}
[ServerCertificateValidationCallback]::Ignore()
#Device Variables
$uri ="https://10.255.254.249/api/"
$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
$config.save("$configname")
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.