How to get notified via email when deployments history of resource groups counts exceeds 500?

Shashikanth M S 40 Reputation points
2024-04-05T11:44:35.09+00:00

we noticed that resource group is limited to 800 deployments in its deployment history.

At the end we have question about Monitoring Part.

PowerShell Script to get list of Resource Group Name along with Deployment Name and Status of all Deployments for all resource group within a Subscription and export as CSV file.

 

# Login to your Azure account

# Set the subscription context

# Get all resource groups in the subscription

# Initialize an array to store successful and failed deployments

  # Get successful and failed deployments for each resource group

  # Add successful and failed deployments to the array

# Export successful and failed deployments to a CSV file

 

 

$resourceGroups = Get-AzResourceGroup

$deploymentsInfo = @()

 

foreach ($resourceGroup in $resourceGroups) {

    $failedDeployments = Get-AzResourceGroupDeployment -ResourceGroupName $resourceGroup.ResourceGroupName | Where-Object { $_.ProvisioningState -eq "Failed" }

    $successfulDeployments = Get-AzResourceGroupDeployment -ResourceGroupName $resourceGroup.ResourceGroupName | Where-Object { $_.ProvisioningState -eq "Succeeded" }

 

    foreach ($deployment in $failedDeployments) {

        $deploymentInfo = [PSCustomObject]@{

            ResourceGroupName = $resourceGroup.ResourceGroupName

            DeploymentName = $deployment.DeploymentName

            ProvisioningState = $deployment.ProvisioningState

            Status = "Failed"

        }

        $deploymentsInfo += $deploymentInfo

    }

 

    foreach ($deployment in $successfulDeployments) {

        $deploymentInfo = [PSCustomObject]@{

            ResourceGroupName = $resourceGroup.ResourceGroupName

            DeploymentName = $deployment.DeploymentName

            ProvisioningState = $deployment.ProvisioningState

            Status = "Successful"

        }

        $deploymentsInfo += $deploymentInfo

    }

}

 

$deploymentsInfo | Export-Csv -Path "AllDeployments.csv" -NoTypeInformation

PowerShell Script to get Only list of Resource group name and count of Failed and Successful Deployments for all resource group within a Subscription and export as CSV file.

# Login to your Azure account Connect-AzAccount # Set the subscription context Set-AzContext -SubscriptionId "

Azure Monitor
Azure Monitor
An Azure service that is used to collect, analyze, and act on telemetry data from Azure and on-premises environments.
3,314 questions
Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,085 questions
Azure Logic Apps
Azure Logic Apps
An Azure service that automates the access and use of data across clouds without writing code.
3,201 questions
Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
1,257 questions
{count} votes

Accepted answer
  1. AnuragSingh-MSFT 21,386 Reputation points
    2024-04-25T06:11:59.9966667+00:00

    @Shashikanth M S Thank you for posting this question in Microsoft Q&A and apologies for the delayed response.

    You are on the right path using the script. At the moment there isn't a direct way to get this alerting enabled for generating alert when the deployment history of RG exceeds a threshold.

    Thus, you may use this script in Azure Automation/logic Apps for it to be run on regular schedule.

    You may include a logic in this script to send email from Azure Automation if the count of deployment history element is above certain threshold.

    You may also suggest this as a feature idea using the following link to our Azure Monitor team for review - Azure Monitor

    Hope this helps.

    If the answer did not help, please add more context/follow-up question for it. Else, if the answer helped, please click Accept answer so that it can help others in the community looking for help on similar topics.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.