-
Notifications
You must be signed in to change notification settings - Fork 0
/
UpdateAzureResourceReviewsFromMonthlyToQuarterly.ps1
79 lines (56 loc) · 2.64 KB
/
UpdateAzureResourceReviewsFromMonthlyToQuarterly.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# Install the AzureAD module if not installed
if (-not (Get-Module -Name AzureAD -ErrorAction SilentlyContinue)) {
Install-Module -Name AzureAD -Force -AllowClobber -Scope CurrentUser
}
if (-not (Get-Module -Name Az -ErrorAction SilentlyContinue)) {
Install-Module -Name Az -AllowClobber -Scope CurrentUser
}
# Import the AzureAD module
Import-Module AzureAD
# Set the subscription and tenant ID
$subscriptionId = "c3e45a88-6154-44ea-8fbb-99de177d2281"
$tenantId = "72f988bf-86f1-41af-91ab-2d7cd011db47"
# Set the API version
$apiVersion = "2021-12-01-preview"
# Construct the URL
$url = "https://management.azure.com/subscriptions/$subscriptionId/providers/Microsoft.Authorization/accessReviewScheduleDefinitions?api-version=$apiVersion"
# Authenticate to Azure using the Az module
Connect-AzAccount -TenantId $tenantId
# Get the access token
$accessToken = (Get-AzAccessToken -ResourceUrl https://management.azure.com).Token
# Make the GET request
$response = Invoke-RestMethod -Uri $url -Method Get -Headers @{
Authorization = "Bearer $accessToken"
}
# Process paginated results
do {
# Make the GET request
$response = Invoke-RestMethod -Uri $url -Method Get -Headers @{
Authorization = "Bearer $accessToken"
}
# Process the results
$response.value | ForEach-Object {
Write-Output "Review Id: $($_.id)"
Write-Output "Recurrence: $($_.properties.settings.recurrence.pattern.type)"
# Clone the object to avoid modifying the original
$tmpBody = $_.PSObject.Copy()
# Modify the recurrence pattern type
$tmpBody.properties.settings.recurrence.pattern.type = "absoluteMonthly"
$tmpBody.properties.settings.recurrence.pattern.interval = 3
# You might need/want to modify this property:
# $tmpBody.properties.settings.instanceDurationInDay = 5
$putUrl = "https://management.azure.com/subscriptions/$subscriptionId/providers/Microsoft.Authorization/accessReviewScheduleDefinitions/$($_.name)?api-version=$apiVersion"
Write-Output $putUrl
$jsonString = $tmpBody | ConvertTo-Json -Depth 10
Write-Output $jsonString
# Make the PUT request to update the Access Review Schedule Definition
$response2 = Invoke-RestMethod -Uri $putUrl -Method Put -Headers @{
Authorization = "Bearer $accessToken"
'Content-Type' = 'application/json'
} -Body $jsonString
}
# Check for the presence of a nextLink
$url = $response.NextLink
} while ($url -ne $null)
# Disconnect from Azure
Disconnect-AzAccount