Sorry for the misunderstanding. I’m no Powershell wizard but basically what you will want to do is:
Use this to get all of the sites
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Accept", "application/json;charset=UTF-8")
$headers.Add("Authorization", "Basic <Base64 encoded creds>")
$response = Invoke-RestMethod 'https://<Your Console>:3780/api/3/sites' -Method 'GET' -Headers $headers
$response | ConvertTo-Json
This will give you all of the sites and then you’ll need to use ConvertFrom-Json
and Select-Object
to grab the specific “id” Property. You can put that into a csv or store it as a variable however you wish.
Once you have all of those variables though, you would move to that next step like you had mentioned and iterate through each of those ids using this query
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Accept", "application/json;charset=UTF-8")
$headers.Add("", "")
$headers.Add("Authorization", "Basic <Base64 encoded creds>")
$response = Invoke-RestMethod 'https://<Your Console>:3780/api/3/sites/$id/alerts/smtp' -Method 'GET' -Headers $headers
$response | ConvertTo-Json
Notice the id variable in the URL
then take the JSON responses from each and use the same ConvertFrom-Json
and Select-Object
to grab only the requests section (stripping the links section) and then use regex to do the find “xyzserver” and replace with “abcserver”.
From there take that edited JSON and use that as the $body variable for the PUT request
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Content-Type", "application/json")
$headers.Add("Accept", "application/json;charset=UTF-8")
$headers.Add("Authorization", "Basic <Base64 encoded creds>")
$body = "[`n {`n `"enabled`": true,`n `"enabledScanEvents`": {`n `"failed`": false,`n `"paused`": false,`n `"resumed`": false,`n `"started`": true,`n `"stopped`": false`n },`n `"enabledVulnerabilityEvents`": {`n `"confirmedVulnerabilities`": true,`n `"potentialVulnerabilities`": true,`n `"unconfirmedVulnerabilities`": true,`n `"vulnerabilitySeverity`": `"any_severity`"`n },`n `"id`": 2,`n `"limitAlertText`": false,`n `"links`": [`n {`n `"href`": `"https://<Your Console>:3780/api/3/sites/6/alerts/smtp/2`",`n `"rel`": `"self`"`n }`n ],`n `"name`": `"Test`",`n `"notification`": `"SMTP`",`n `"recipients`": [`n `"test@test.com`"`n ],`n `"relayServer`": `"3.4.5.6`",`n `"senderEmailAddress`": `"test@test.com`"`n }`n ]"
$response = Invoke-RestMethod 'https://<Your Console>:3780/api/3/sites/$id/alerts/smtp' -Method 'PUT' -Headers $headers -Body $body
$response | ConvertTo-Json
.
.
.
So those three requests should get you started, you just need to figure out the Powershell bits to do the iteration and find and replace.
I hope this helps!