1+ <#
2+
3+ . SYNOPSIS
4+ This sample script demonstrates the use of NetBackup REST API for listing the backup images.
5+
6+ . DESCRIPTION
7+ This script will get a list of backup images in the last 24 hours and print the details of the last 10 images in a tabular format.
8+
9+
10+ . EXAMPLE
11+ ./Get-NB-Images.ps1 -nbmaster "nb-master.example.com" -username "administrator" -password "secret"
12+
13+ #>
14+
15+ param (
16+ [string ]$nbmaster = $ (throw " Please specify the name of NetBackup master server using -nbmaster parameter." ),
17+ [string ]$username = $ (throw " Please specify the user name using -username parameter." ),
18+ [string ]$password = $ (throw " Please specify the password using -password parameter." )
19+ )
20+
21+ # ####################################################################
22+ # Initial Setup
23+ # Note: This allows self-signed certificates and enables TLS v1.2
24+ # ####################################################################
25+
26+ function InitialSetup ()
27+ {
28+ # Allow self-signed certificates
29+ if ([System.Net.ServicePointManager ]::CertificatePolicy -notlike ' TrustAllCertsPolicy' )
30+ {
31+ Add-Type - TypeDefinition @"
32+ using System.Net;
33+ using System.Security.Cryptography.X509Certificates;
34+ public class TrustAllCertsPolicy : ICertificatePolicy {
35+ public bool CheckValidationResult(
36+ ServicePoint srvPoint, X509Certificate certificate,
37+ WebRequest request, int certificateProblem) {
38+ return true;
39+ }
40+ }
41+ "@
42+ [System.Net.ServicePointManager ]::CertificatePolicy = New-Object - TypeName TrustAllCertsPolicy
43+
44+ # Force TLS v1.2
45+ try {
46+ if ([Net.ServicePointManager ]::SecurityProtocol -notcontains ' Tls12' ) {
47+ [Net.ServicePointManager ]::SecurityProtocol += [Net.SecurityProtocolType ]::Tls12
48+ }
49+ }
50+ catch {
51+ Write-Host $_.Exception.InnerException.Message
52+ }
53+ }
54+ }
55+
56+ InitialSetup
57+
58+ # ####################################################################
59+ # Global Variables
60+ # ####################################################################
61+
62+ $port = 1556
63+ $basepath = " https://" + $nbmaster + " :" + $port + " /netbackup"
64+ $content_type = " application/vnd.netbackup+json;version=1.0"
65+
66+ # ####################################################################
67+ # Login
68+ # ####################################################################
69+
70+ $uri = $basepath + " /login"
71+
72+ $body = @ {
73+ userName = $username
74+ password = $password
75+ }
76+
77+ $response = Invoke-WebRequest `
78+ - Uri $uri `
79+ - Method POST `
80+ - Body (ConvertTo-Json - InputObject $body ) `
81+ - ContentType $content_type
82+
83+ if ($response.StatusCode -ne 201 )
84+ {
85+ throw " Unable to connect to the Netbackup master server!"
86+ }
87+
88+ $content = (ConvertFrom-Json - InputObject $response )
89+
90+ # ####################################################################
91+ # Get NetBackup Images
92+ # ####################################################################
93+
94+ $uri = $basepath + " /catalog/images"
95+
96+ $headers = @ {
97+ " Authorization" = $content.token
98+ }
99+
100+ $query_params = @ {
101+ # "page[limit]" = 100 # This changes the default page size to 100
102+ # "filter" = "policyType eq 'VMware'" # This adds a filter to only show VMware backup images
103+ }
104+
105+ $response = Invoke-WebRequest `
106+ - Uri $uri `
107+ - Method GET `
108+ - Body $query_params `
109+ - ContentType $content_type `
110+ - Headers $headers
111+
112+ if ($response.StatusCode -ne 200 )
113+ {
114+ throw " Unable to get the list of Netbackup images!"
115+ }
116+
117+ $content = (ConvertFrom-Json - InputObject $response )
118+
119+ # This prints all the available attributes
120+ # $content.data.attributes | Format-Table -AutoSize
121+
122+ $properties =
123+ @ {Label = " Image ID" ; Expression = { $_.id }},
124+ @ {Label = " Policy" ; Expression = { $_.attributes.policyName }},
125+ @ {Label = " Client" ; Expression = { $_.attributes.clientName }},
126+ @ {Label = " Backup Time" ; Expression = { $_.attributes.backupTime }}
127+
128+ $content.data | Format-Table - AutoSize - Property $properties
0 commit comments