-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
Segment/Identity Management/Add-ClientsToIdentityLearning.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |