Remove Storage Account and VHD refs (#8581)

This commit is contained in:
Shamil Mubarakshin
2023-10-18 19:11:46 +02:00
committed by GitHub
parent e78225c349
commit e9fc71683f
4 changed files with 23 additions and 241 deletions

View File

@@ -1,23 +1,19 @@
param(
[String] [Parameter (Mandatory=$true)] $TempResourceGroupName,
[String] [Parameter (Mandatory=$true)] $StorageAccount,
[String] [Parameter (Mandatory=$true)] $SubscriptionId,
[String] [Parameter (Mandatory=$true)] $ClientId,
[String] [Parameter (Mandatory=$true)] $ClientSecret,
[String] [Parameter (Mandatory=$true)] $TenantId
[Parameter (Mandatory=$true)] [string] $TempResourceGroupName,
[Parameter (Mandatory=$true)] [string] $SubscriptionId,
[Parameter (Mandatory=$true)] [string] $ClientId,
[Parameter (Mandatory=$true)] [string] $ClientSecret,
[Parameter (Mandatory=$true)] [string] $TenantId
)
az login --service-principal --username $ClientId --password $ClientSecret --tenant $TenantId | Out-Null
az account set --subscription $SubscriptionId | Out-Null
$groupExist = az group exists --name $TempResourceGroupName --subscription $SubscriptionId
$groupExist = az group exists --name $TempResourceGroupName
if ($groupExist -eq "true") {
$osDiskName = az deployment group list --resource-group $TempResourceGroupName --query "[].properties.parameters.osDiskName.value" -o tsv
Write-Host "Found a match, deleting temporary files"
az group delete --name $TempResourceGroupName --subscription $SubscriptionId --yes | Out-Null
az group delete --name $TempResourceGroupName --yes | Out-Null
Write-Host "Temporary group was deleted successfully"
Write-Host "Deleting OS disk"
az storage remove --account-name $StorageAccount -c "images" -n "$osDiskName.vhd" --only-show-errors | Out-Null
Write-Host "OS disk deleted"
} else {
Write-Host "No temporary groups found"
}
}