In this post, I want to show you how you remove an Azure Resource Group with PowerShell using MS GRAPH API.
Some of the Use cases❗
✔️Delegate the Azure Resource Group deletion
✔️Control your Azure Resource Group outside Azure Portal.
✔️Mass deletion Azure of Resource Groups
✔️Many more…
API Reference and Permissions
We used the following Docs to get this Script up and running
and configured the Azure App Registration as needed
To learn more from Microsoft GRAPH API, see my Blog Series:
Part 1 – Authentication and Azure App – Use Microsoft Graph API with PowerShell – Part 1 » TechGuy
Part 2 – Oauth2.0 – Use Microsoft Graph API with PowerShell – Part 2 » TechGuy
Part 3 – First Powershell Script to get a Teams Lis and Walkthrough – Use Microsoft Graph API with PowerShell – Part 3 » TechGuy
Part 4 – this one – Use Microsoft Graph API with PowerShell – Part 4 » TechGuy
The Script
$applicationId = 'your Application ID'
$tenantId = 'your Tenant ID'
$secret = 'your Secret'
$subscriptionId = 'your Subscription ID'
#VM Details
$RessourceGroupName = "RG_TEST_RessourceGroup"
#API Version
$apiversion="2021-04-01"
#Microsoft Azure Rest API authentication
#https://docs.microsoft.com/en-us/rest/api/azure/
$param = @{
Uri = "https://login.microsoftonline.com/$tenantId/oauth2/token?api-version=$apiversion";
Method = 'Post';
Body = @{
grant_type = 'client_credentials';
resource = 'https://management.core.windows.net/';
client_id = $applicationId;
client_secret = $secret
}
}
$result = Invoke-RestMethod @param
$token = $result.access_token
$headers = @{
"Authorization" = "Bearer $($token)"
"Content-type" = "application/json"
}
#Remove RessoruceGroup
$URL = "https://management.azure.com/subscriptions/$subscriptionId/resourceGroups/$($RessourceGroupName)?api-version=$apiversion"
Invoke-RestMethod -Method DELETE -URI $URL -headers $headers
GitHub Repo
Here you can find the GitHub Repo with a lot of other examples: Seidlm/Microsoft-Azure: Azure Rest API Examples (github.com)
Delegate to remove an Azure Resource Group as Self Service with au2mator
With au2mator Self Service Portal, you can create a Service and delegate the task to create an Azure Resource Group.
Some of the Use cases❗
✔️Delegate the Azure Resource Group deletion
✔️Control your Azure Resource Group outside Azure Portal.
✔️Mass deletion Azure of Resource Groups
✔️Approve a Resource Group deletion
✔️Many more…
More Details: www.au2mator.com
Michael Seidl aka Techguy
au2mate everything