Backup Using Powershell

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Backup Using Powershell

L4 Transporter

add-type @"
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class TrustAllCertsPolicy : ICertificatePolicy {
public bool CheckValidationResult(
ServicePoint srvPoint, X509Certificate certificate,
WebRequest request, int certificateProblem) {
return true;
}
}
"@
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy

$ErrorActionPreference = "SilentlyContinue"
$BACKUP_DIR = "d:\work\temp\"

function getConfiguration () {

Param(
[string]$IP,
[string]$HOSTNAME,
[string]$KEY
)

$URL = "https://" + $IP + "/esp/restapi.esp?type=export&category=configuration&from=running-config.xml&key=" + $KEY
$TIMESTAMP = Get-Date -format dd-MM-yyyy
$PATH = $BACKUP_DIR + $TIMESTAMP + "_" + $HOSTNAME + "_" + $IP + ".xml"
Invoke-WebRequest -Uri $URL -OutFile $PATH

}

getConfiguration "1.1.1.1" "Boston" "<API KEY>"
getConfiguration "2.2.2.2" "Florida" "<API KEY>"

<#
Generate the API Key Using
https://<PA IP>/esp/restapi.esp?type=keygen&user=<username case sensetive>&password=<url encoded password>
#<

1 REPLY 1

L1 Bithead

Awesome - I've also scripted this by myself yesterday - more or less the same code 🙂

 

One addition: if you work with Panorama you should export the device state on the local boxes. If you only export the running-config it will only include the locally configured settings and not the settings pushed by Panorama. Just use following API query:

 

/api/?type=export&category=device-state&key=...

  • 3290 Views
  • 1 replies
  • 1 Likes
Like what you see?

Show your appreciation!

Click Like if a post is helpful to you or if you just want to show your support.

Click Accept as Solution to acknowledge that the answer to your question has been provided.

The button appears next to the replies on topics you’ve started. The member who gave the solution and all future visitors to this topic will appreciate it!

These simple actions take just seconds of your time, but go a long way in showing appreciation for community members and the LIVEcommunity as a whole!

The LIVEcommunity thanks you for your participation!