PowerShell Script to Pull Advisory Information
Below is a sample PowerShell script to pull advisory information:
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
#Max number of advistories to pull
$global:QueryLimit = 20
function QueryData ($URL, $Header)
{
# Get First Page of results (20 items)
$result = @()
$results = @()
try
{
$result = Invoke-RestMethod ($URL) -Method Get -Headers $Header
$results = $result.results
if ($result.results)
{
$results = $result.results
}
else
{
$results = $result
}
}
catch
{
Write-host ("Error QueryData1 " + $URL + " " + $_.Exception.Message + " " + $_.Exception.ItemName) -ForegroundColor Red
}
#Get the next pages of results, if any
while (![string]::IsNullOrWhiteSpace($result.next))
{
try
{
$result = Invoke-RestMethod $result.next -Method Get -Headers $Header
$results += $result.results
if ($results.count -gt $global:QueryLimit)
{
break;
}
}
catch
{
Write-host ("Error QueryData2 " + $URL + $result.next + " " + $_.Exception.Message + " " + $_.Exception.ItemName) -ForegroundColor Red
return $results
}
}
return $results
}
function CallAPI ($URL, $Header)
{
$Collection = QueryData $URL $Header
foreach ($Advistory in $Collection)
{
#$Advistory
$advisoryDetails = QueryData ("https://api.app.flexerasoftware.com/api/advisories/" + $Advistory.id +"/") $Header
$advisoryDetails
#Remove this and it will loop over the first $global:QueryLimit advistories and stop
break;
}
}
$WebServiceHeader = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$WebServiceHeader.Add("Content-Type", 'application/json')
$WebServiceHeader.Add("Authorization", "Token YOURTOKENHERE" )
CallAPI "https://api.app.flexerasoftware.com/api/advisories/" $WebServiceHeader