-
Notifications
You must be signed in to change notification settings - Fork 251
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hydration kits updates, ALZ fixes (#684)
Co-authored-by: Anthony Watherston <[email protected]>
- Loading branch information
Showing
12 changed files
with
249 additions
and
138 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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,42 @@ | ||
function Remove-HydrationChildHierarchy { | ||
[CmdletBinding()] | ||
param ( | ||
[Parameter(Mandatory = $true)] | ||
$ChildHierarchy | ||
) | ||
foreach ($child in $ChildHierarchy) { | ||
if ($child.Type -eq "Microsoft.Management/managementGroups") { | ||
# Error action included because timeouts happen frequently, but mean nothing. Rather than have responses cause concern, we simply suppress the error. | ||
if ($child.children) { | ||
Write-Information " Removing child objects of $($child.Name) -- $($child.children.Name -join ", ")..." | ||
try { | ||
Write-Debug "Starting Inner Loop" | ||
$null = Remove-HydrationChildHierarchy -ChildHierarchy $child.children #-erroraction silentlycontinue | ||
Write-Debug "Leaving Inner Loop" | ||
} | ||
catch { | ||
write-error $_ | ||
} | ||
} | ||
do { | ||
Write-Information " Removing $($child.Name)..." | ||
$null = Remove-AzManagementGroup -GroupName $($child.Name) | ||
try { | ||
$null = Get-AzManagementGroupRestMethod -GroupId $($child.Name) -ErrorAction SilentlyContinue | ||
} | ||
catch { | ||
if ($_.Exception.Message -match "NotFound") { | ||
Write-Information " $($child.Name) confirmed to be removed..." | ||
$complete = $true | ||
} | ||
else { | ||
Write-Information " $($child.Name) generated an error during deletion, retrying $(6-$i) more times..." | ||
$complete = $false | ||
$i++ | ||
} | ||
} | ||
# } | ||
}until($true -eq $complete -or $i -eq 6) | ||
} | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
Scripts/Helpers/RestMethods/Get-AzManagementGroupRestMethod.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,46 @@ | ||
|
||
function Get-AzManagementGroupRestMethod { | ||
[CmdletBinding()] | ||
param ( | ||
[string] $ApiVersion = "2020-05-01", | ||
[switch] $Expand, | ||
[switch] $Recurse, | ||
[string] $GroupID | ||
) | ||
|
||
# Print a message to indicate that the function is being called | ||
Write-Debug "Get-AzManagementGroupRestMethod is being called" | ||
|
||
# Assemble the API path | ||
$path = "/providers/Microsoft.Management/managementGroups/$($GroupID)?api-version=$($ApiVersion)" | ||
if ($Recurse) { | ||
$path += "&`$recurse=True" | ||
} | ||
if ($Expand) { | ||
$path += "&`$expand=children" | ||
} | ||
|
||
# Print the GroupID and API path for debugging | ||
Write-Debug "GroupID: $GroupID" | ||
Write-Debug "API Path: $path" | ||
|
||
# Invoke the REST API | ||
$response = Invoke-AzRestMethod -Path $path -Method GET | ||
|
||
# Process response | ||
$statusCode = $response.StatusCode | ||
if ($statusCode -lt 200 -or $statusCode -ge 300) { | ||
$content = $response.Content | ||
Write-Error "Get Management Group error $($statusCode) -- $($content)" -ErrorAction Stop | ||
} | ||
|
||
# Convert the response content to a JSON object | ||
$jsonContent = $response.Content | ConvertFrom-Json -Depth 100 | ||
|
||
# $jsonText = $jsonContent | ConvertTo-Json -Depth 100 | ||
|
||
return $jsonContent | ||
} | ||
|
||
|
||
|
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
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
Oops, something went wrong.