Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create get-StatusDates.ps1 #8

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions Segment/Asset Management/get-StatusDates.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
$APIKey = "<INSERT_API_KEY>"

#Headers
$znHeaders = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$znHeaders.Add("Authorization",$APIKey)
$znHeaders.Add("content-type","application/json")


$uri = "https://portal.zeronetworks.com/api/v1"


function Show-AssetsDates {
param (
$status = "monitored" # Define a default value for the status parameter
)

Write-Output "--------------Fetching dates for $status Assets..."

# Use $status variable in the API string
$apiString = "assets/$($status)?_limit=1&_offset=0&_filters=&order=asc&orderColumns[]=name&showInactive=false&with_count=true"
$assetsToCheck = @()

# Get the total number of assets
$allAssets = Invoke-RestMethod -Uri "$uri/$apiString" -Method Get -Headers $znHeaders

$i = 0

# Page through results if needed
for (; $i -le ($allAssets.Count);) {
$assetsToCheck += (Invoke-RestMethod -Uri "$uri/assets/$($status)?_limit=400&_offset=$i&_filters=&with_count=true&order=asc&orderColumns[]=name" -Method Get -Headers $znHeaders).items
$i = $i + 400
}

# Get Audit data for assets in the specified status
foreach ($lasset in $assetsToCheck) {
$apiString = "assets/$($lasset.id)/audit?_limit=30&_cursor=&_search=&_filters=[%7B%22id%22:%22auditType%22,%22includeValues%22:[%227%22,%2244%22],%22excludeValues%22:[]%7D]&order=desc"
$audits = Invoke-RestMethod -Uri "$uri/$apiString" -Method Get -Headers $znHeaders
Write-Host $lasset.name $audits.items[0].isoTimestamp | FT
}
}

# Show Monitored Assets
Show-AssetsDates -status "monitored"
# Show Learning Assets
Show-AssetsDates -status "queued"
# Show Segmented Assets
Show-AssetsDates -status "protected"
Loading