<# .EXAMPLE ./Get-NB-Images.ps1 -nbmaster "nbmaster" -apikey "apikey" #> param ( [string]$nbmaster = $(throw "Please specify the name of NetBackup master server using -nbmaster parameter."), [string]$apikey = $(throw "Please specify the API Key using the -apikey parameter.") ) ##################################################################### # Initial Setup # Note: This allows self-signed certificates and enables TLS v1.2 ##################################################################### function InitialSetup() { # Allow self-signed certificates if ([System.Net.ServicePointManager]::CertificatePolicy -notlike 'TrustAllCertsPolicy') { Add-Type -TypeDefinition @" 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 -TypeName TrustAllCertsPolicy # Force TLS v1.2 try { if ([Net.ServicePointManager]::SecurityProtocol -notcontains 'Tls12') { [Net.ServicePointManager]::SecurityProtocol += [Net.SecurityProtocolType]::Tls12 } } catch { Write-Host $_.Exception.InnerException.Message } } } InitialSetup ##################################################################### # Global Variables ##################################################################### $port = 1556 $basepath = "https://" + $nbmaster + ":" + $port + "/netbackup" $content_type = "application/vnd.netbackup+json;version=5.0" ##################################################################### # CURL ##################################################################### $uri = $basepath + "/admin/jobs" $headers = @{ "Authorization" = $apikey "Cache-Control" = "no cache" } $offset = 0 $failures=0 $numJobs=0 $next = $true ####Date#### $currentDate = Get-Date $currentDate = $currentDate.ToString('MM-dd-yyyy') ############ while($next){ $query_params = @{ "page[limit]" = 100 #Default is 10 "page[offset]" = $offset # Default value is 0 #test filter for only snapshots #filter="jobType eq 'SNAPSHOT'" } $response = Invoke-WebRequest ` -Uri $uri ` -Method GET ` -Body $query_params ` -ContentType $content_type ` -Headers $headers if ($response.StatusCode -ne 200) { throw "Unable to curl!" } $content = (ConvertFrom-Json -InputObject $response) $properties = @{Label = "JobID"; Expression = { $_.attributes.jobID}}, @{Label = ";"; Expression = { ";"}}, @{Label = "JobType"; Expression = { $_.attributes.jobType}}, @{Label = ";"; Expression = { ";"}}, @{Label = "PolicyType"; Expression = { $_.attributes.jobType}}, @{Label = ";"; Expression = { ";"}}, @{Label = "Schedule"; Expression = { $_.attributes.scheduleName}}, @{Label = ";"; Expression = { ";"}}, @{Label = "Client"; Expression = { $_.attributes.clientName}}, @{Label = ";"; Expression = { ";"}}, @{Label = "AssetName"; Expression = { $_.attributes.assetDisplayableName}}, @{Label = ";"; Expression = { ";"}}, @{Label = "StartTime"; Expression = { $_.attributes.startTime}}, @{Label = ";"; Expression = { ";"}}, @{Label = "EndTime"; Expression = { $_.attributes.endTime}}, @{Label = ";"; Expression = { ";"}}, @{Label = "ElaspedTime"; Expression = { $_.attributes.enlapsedTime}}, @{Label = ";"; Expression = { ";"}}, @{Label = "Status Code"; Expression = { $_.attributes.status}} #$chart= $content.data | format-table -autosize -property $properties #just outputs the results to the window Write-Output $content.data | format-table -autosize -property $properties #uncomment to export results #$content.data | Format-Table -AutoSize -Property $properties | out-file C:\example.csv -append $offset = $offset + $content.meta.pagination.limit if($content.meta.pagination.next -eq $null) { $next = $false } }