Skip to content

Commit

Permalink
Add-ClientsToIdentityLearning
Browse files Browse the repository at this point in the history
  • Loading branch information
dicolanl authored Jun 26, 2024
1 parent 1172346 commit 0519d48
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions Segment/Identity Management/Add-ClientsToIdentityLearning.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
$apiKey = ''

if (-not(Get-Module -ListAvailable -Name ZeroNetworks)) {
Install-Module ZeroNetworks -scope CurrentUser
}

Import-Module ZeroNetworks

Set-ZNApiKey -ApiKey $apiKey

#Get the client system group
$clientsGroup = (Get-ZNGroup -Search clients).Items | where {$_.id -like "g:s:*"}

#build filter Idseg is not segmented and memberOf Clients group.
$filters = '[{"id":"identityProtectionStatus","includeValues":["1"],"excludeValues":[]},{"id":"nestedMemberOf","includeValues":["'+($clientsGroup.Id)+'"],"excludeValues":[]}]'

#get the count of assets
$count = (Get-ZNAssetsMonitored -Limit 1 -filters $filters -WithCount).Count

#loop to get all the asset Ids that match the filter.
$offset = 0
$assets = @()
while ($offset -lt $count) {
$assets += (Get-ZNAssetsMonitored -Limit 400 -Offset $offset -Filters $filters).Items
$offset += 400
}

#Batch the assets into id learning
$batch = 0
$counter = 0
$batchAssets = @()
while ($counter -le $assets.Count) {
$batchAssets += $assets[$counter].Id
$counter++
$batch++
if($batch -eq 100){
$body = @{
"items" = $batchAssets
"queueDays" = 30
}
Invoke-RestMethod -uri "https://portal.zeronetworks.com/api/v1/assets/identity-actions/queue" -Headers @{"Authorization" = $apiKey; "Content-Type" = "application/json"} -Method Post -Body ($body | ConvertTo-Json)
$body = $null
$batch = 0
}
}

0 comments on commit 0519d48

Please sign in to comment.