Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Fetch the resources tagged in a pid-[GUID] deployment
This is an update of the original script to work with the Az PowerShell module:
Use this script to retrieve the resources that were deployed with a pid-[GUID] tag
Select-AzSubscription before running the script - it must be run within the subscription context of the deployment
The GUID and resourceGroup name of the deployment are required params
#get the correlationId of the pid deployment
$correlationId = (Get-AzResourceGroupDeployment -ResourceGroupName $resourceGroupName -Name "pid-$guid").correlationId
#find all deployments with that correlationId
$deployments = Get-AzResourceGroupDeployment -ResourceGroupName $resourceGroupName | Where-Object{$_.correlationId -eq $correlationId}
#find all deploymentOperations in a deployment by name (since PowerShell does not surface outputResources on the deployment or correlationId on the deploymentOperation)
foreach ($deployment in $deployments){
#get deploymentOperations by deploymentName and then the resourceId for any create operation
($deployment | Get-AzResourceGroupDeploymentOperation | Where-Object{$ -eq "Create" -and $ -ne "Microsoft.Resources/deployments"})
Copy link

This script doesn't work in my environment using Az 5.2.0.
I think it's because the return value of Get-AzResourceGroupDeploymentOperation has changed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment