<# .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" $uuid_master = "xxx" # uuid has to be uniq for each master server ##################################################################### # Get NetBackup Master Server Services ##################################################################### Write-Host "`nGet NetBackup Master Server Services`n" $uri = $basepath + "/admin/hosts/$uuid_master/services" $headers = @{ "Authorization" = $apikey } $response = Invoke-WebRequest ` -Uri $uri ` -Method GET ` -Body $query_params ` -ContentType $content_type ` -Headers $headers if ($response.StatusCode -ne 200) { throw "Unable to get the Netbackup jobs!" } $content = (ConvertFrom-Json -InputObject $response) # This prints all the available attributes #$content.data.attributes | Format-Table -AutoSize $properties = @{Label = "Service ID"; Expression = { $_.id }}, @{Label = "Status"; Expression = { $_.attributes.status }} $content.data | Format-Table -AutoSize -Property $properties ##################################################################### # Get NetBackup Master Server Processes ##################################################################### Write-Host "`nGet NetBackup Master Server Processes`n" $uri = $basepath + "/admin/hosts/$uuid_master/processes" $headers = @{ "Authorization" = $apikey } $response = Invoke-WebRequest ` -Uri $uri ` -Method GET ` -Body $query_params ` -ContentType $content_type ` -Headers $headers if ($response.StatusCode -ne 200) { throw "Unable to get the Netbackup jobs!" } $content = (ConvertFrom-Json -InputObject $response) # This prints all the available attributes #$content.data.attributes | Format-Table -AutoSize $properties = @{Label = "Process PID"; Expression = { $_.attributes.pid }}, @{Label = "Process Name"; Expression = { $_.attributes.processName }}, @{Label = "Memory Usage"; Expression = { $_.attributes.memoryUsageMB }} $content.data | Format-Table -AutoSize -Property $properties ##################################################################### # Get NetBackup Alerts (Last 7 days) ##################################################################### Write-Host "`nGet NetBackup Alerts (Last 7 days)`n" $uri = $basepath + "/manage/alerts" $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="createdDateTime 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 get the Netbackup jobs!" } $content = (ConvertFrom-Json -InputObject $response) # This prints all the available attributes #$content.data.attributes | Format-Table -AutoSize $properties = @{Label = "Category"; Expression = { $_.attributes.params.startTime }}, @{Label = "Job ID"; Expression = { $_.attributes.params.jobId }}, @{Label = "Errors"; Expression = { $_.attributes.params.errorMsg }}, @{Label = "Start time"; Expression = { $_.attributes.params.startTime }}, @{Label = "End time"; Expression = { $_.attributes.params.endTime }}, @{Label = "Status"; Expression = { $_.attributes.status }} $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:\Users\veritas\Desktop\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 } } ##################################################################### # Get Netbackup Jobs (Last 7 days) ##################################################################### Write-Host "`nGet NetBackup Jobs (Last 7 days)`n" $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 } }