-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremove-all.ps1
74 lines (59 loc) · 2.46 KB
/
remove-all.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
$prefix=$Env:DeployPrefix
$account=$(az account show --output json)| ConvertFrom-Json
if($LASTEXITCODE -ne 0){
Write-Host -ForegroundColor Green 'Please login to Azure'
az login
$account=$(az account show --output json)| ConvertFrom-Json
}
# List available subscriptions
$subscriptions = az account list --query "[].{Name:name, Id:id}" --output json | ConvertFrom-Json
if ($subscriptions.Count -eq 0) {
Write-Error "No subscriptions found in the current Azure account."
exit 1
}
# Ensure correct subscription is used if there is more than 1 subscription
if($subscriptions.Count -gt 1){
Write-Host -ForegroundColor Green "These are your Azure subscriptions:"
$index=1
$default=1
$subscriptions | ForEach-Object {
if( $_.Id -eq $account.id){
$default=$index
Write-Host -ForegroundColor Yellow "[$index] $($_.Name) : $($_.Id)"
}
else {
Write-Host "[$index] $($_.Name) : $($_.Id)"
}
$index += 1
}
# Prompt the user to select a subscription
Write-Host
Write-Host -ForegroundColor Yellow "Enter the index of the subscription you want to use (default is $default)" -NoNewline
$subscriptionIndex = Read-Host
if( $subscriptionIndex -lt 0 ){
$subscriptionIndex=$default
}
# Get the selected subscription
$selectedSubscription = $subscriptions[$subscriptionIndex-1]
if (-not $selectedSubscription) {
exit 1
}
if( $selectedSubscription.Id -ne $account.Id ){
# Set the selected subscription as the current subscription
az account set --subscription $selectedSubscription.Id
Write-Host -ForegroundColor Green "Successfully selected subscription: $($selectedSubscription.Name)"
}
Write-Host ""
}
Write-Host -ForegroundColor Yellow "Please enter a resource prefix. This should be a short text starting with a letter (default $prefix): "
$prefix = Read-Host;
if( $prefix -ne '')
{
$prefix=$prefix;
}
$Env:DeployPrefix=$prefix # Set the environment variable for the next script
Write-Host -ForegroundColor Yellow "⚠️ Removing resource group $prefix-app-dev and $prefix-infra-dev. Press any key to continue or Ctrl+C to cancel."
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
az group delete --name "$prefix-app-dev" --no-wait --yes
az group delete --name "$prefix-infra-dev" --no-wait --yes
Write-Host -ForegroundColor Green "Resource removal in progress. This may take a few minutes."