Changed remove resource to async

This commit is contained in:
Alexander (Sasha) Nosov
2023-04-08 11:18:28 -07:00
parent 751b7a2db0
commit aadcf2522c
3 changed files with 9 additions and 7 deletions
@@ -108,6 +108,7 @@ Update-AzConfig -DisplayBreakingChangeWarning $false
# Load required modules # Load required modules
$requiredModules = @( $requiredModules = @(
"AzureAD",
"Az.Accounts", "Az.Accounts",
"Az.ConnectedMachine", "Az.ConnectedMachine",
"Az.ResourceGraph" "Az.ResourceGraph"
@@ -84,10 +84,10 @@ This option is recommended because Cloud shell has the Azure PowerShell modules
curl https://raw.githubusercontent.com/microsoft/sql-server-samples/master/samples/manage/azure-arc-enabled-sql-server/uninstall-azure-extension-for-sql-server/uninstall-azure-extension-for-sql-server.ps1 -o uninstall-azure-extension-for-sql-server.ps1 curl https://raw.githubusercontent.com/microsoft/sql-server-samples/master/samples/manage/azure-arc-enabled-sql-server/uninstall-azure-extension-for-sql-server/uninstall-azure-extension-for-sql-server.ps1 -o uninstall-azure-extension-for-sql-server.ps1
``` ```
1. Run the script. 1. Run the script using the desired scope. For example:
```console ```console
.\uninstall-azure-extension-for-sql-server.ps1 -SubId ALL .\uninstall-azure-extension-for-sql-server.ps1 -SubId <sub_id>
``` ```
> [!NOTE] > [!NOTE]
@@ -124,8 +124,8 @@ Use the following steps to run the script in a PowerShell session on your PC.
Connect-AzAccount -TenantID (Get-AzureADTenantDetail).ObjectId Connect-AzAccount -TenantID (Get-AzureADTenantDetail).ObjectId
``` ```
1. Run the script using the desired scope. 1. Run the script using the desired scope. For example:
```console ```console
.\uninstall-azure-extension-for-sql-server.ps1 -All $True .\uninstall-azure-extension-for-sql-server.ps1 -SubId <sub_id> -ResourceGroup <resource_group>
``` ```
@@ -88,7 +88,7 @@ foreach ($sub in $subscriptions){
try { try {
Set-AzContext -SubscriptionId $sub.Id Set-AzContext -SubscriptionId $sub.Id
}catch { }catch {
write-host "[Environment]::NewLine + Invalid subscription: $($sub.Id)" write-host ([Environment]::NewLine + "Invalid subscription: $($sub.Id)")
{continue} {continue}
} }
@@ -142,8 +142,9 @@ foreach ($sub in $subscriptions){
$resources = Search-AzGraph -Query "$($query2)" $resources = Search-AzGraph -Query "$($query2)"
foreach ($r in $resources) { foreach ($r in $resources) {
Remove-AzResource -ResourceId $r.resourceId -Force | Out-Null $job = Remove-AzResource -ResourceId $r.resourceId -Force -AsJob | Out-Null
write-host ([Environment]::NewLine + "Removing resource: $($r.resourceId)")
} }