<# .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 $check = $true ####Date#### $currentDate = Get-Date $pastDate = (Get-Date).AddDays(-7) $pastDate = $pastDate.ToString('yyyy-MM-ddThh:mm:ss.000Z') ############ while($check){ $query_params = @{ "page[limit]" = 100 #Default is 10 "page[after]" = $next # Default value is 0 filter="startTime gt $pastDate" #sorts by ascending, default is descending #"sort" = 'startTime' } $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}} Write-Output $content.data | format-table -autosize -property $properties #uncomment and change file name if you want results exported #$content.data | Format-Table -AutoSize -Property $properties | out-file C:exportfilename.csv -append $offset = $offset + $content.meta.pagination.limit $realNext = $content.meta.pagination.next $realPrev = $content.meta.pagination.prev $splitNext = $realNext -split ":" $intNext = [int]$splitNext[1] + $offset $a = $splitNext[0], $intNext $next = $a -join ":" if($content.meta.pagination.next -eq $null) { $check= $false } }