Hey Script! Ask me first before you delete my Azure service.

Vijay Borkar (VBCloudboy)
2 min readMay 17, 2021
https://unsplash.com/photos/qGaYbngEtlE?utm_source=unsplash&utm_medium=referral&utm_content=creditShareLink

Sometimes we did not want our scripts to be executed in an unattended mode. But if we think that our end customers can understand all the algorithms and logic you poured in your scripts and it will be 1-step easy thing to understand, then my friends you are very wrong.

Let’s not be presumptuous and build things by only considering the core logic. I have prepared a PowerShell script which will capture information on Azure DNS Service and then prompt for our inputs and then it will proceed to either delete or keep it.

  1. First we will declare the variables.
#----- DECLARE THE VARIABLES -------#$dnsList = Get-AzDnsZone
$dnsResGrpName = "02demo"
$choices = New-Object Collections.ObjectModel.Collection[Management.Automation.Host.ChoiceDescription]
$choices.Add((New-Object Management.Automation.Host.ChoiceDescription -ArgumentList '&Yes'))
$choices.Add((New-Object Management.Automation.Host.ChoiceDescription -ArgumentList '&No'))

2. Then we will run the Logic which will serve the end results

foreach ($dnszone in $dnsList.Name ){$CustomerInputs = Read-Host -Prompt "Should proceed deleting DNS zone name - $dnszone Enter Y/N "
if ($CustomerInputs -eq "Y") {

Write-Host 'Deleting DNS Zone' $dnszone 'is Confirmed' -ForegroundColor Yellow
Remove-AzDnsZone -Name $dnszone -ResourceGroupName $dnsResGrpName
Write-Host 'Deleting DNS Zone' $dnszone 'Completed Successfully' -ForegroundColor Green
} else {
Write-Host 'Deleting DNS Zone' $dnszone 'is Cancelled' -ForegroundColor Gray
}
}

3. In the end your script will display results as shown below;

4. A quick glimpse of whole script in your code editors looks something like Image below;

Now, you guys can use similar logic to any other azure service and get the script working in an attended mode.

--

--

Vijay Borkar (VBCloudboy)

Assisting Microsoft partners in elevating their technical capabilities in AI, analytics, and cybersecurity. Collaborating with them to create innovative product