Skip to content

Instantly share code, notes, and snippets.

@bmoore-msft
Last active June 7, 2024 09:34
Show Gist options
  • Save bmoore-msft/ae6b8226311014d6e7177c5127c7eba1 to your computer and use it in GitHub Desktop.
Save bmoore-msft/ae6b8226311014d6e7177c5127c7eba1 to your computer and use it in GitHub Desktop.
Fetch the resources tagged in a pid-[GUID] deployment
Param(
[string][Parameter(Mandatory=$true)]$deploymentName, # the full name of the deployment, e.g. pid-XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
[string][Parameter(Mandatory=$true)]$resourceGroupName
)
# Get the correlationId of the named deployment
$correlationId = (Get-AzResourceGroupDeployment -ResourceGroupName $resourceGroupName -Name "$deploymentName").correlationId
# Find all deployments with that correlationId
$deployments = Get-AzResourceGroupDeployment -ResourceGroupName $resourceGroupName | Where-Object{$_.correlationId -eq $correlationId}
# Find all deploymentOperations in all deployments with that correlationId as PowerShell doesn't surface outputResources on the deployment or correlationId on the deploymentOperation
foreach ($deployment in $deployments){
# Get deploymentOperations by deploymentName
# then the resourceIds for each resource
($deployment | Get-AzResourceGroupDeploymentOperation | Where-Object{$_.targetResource -notlike "*Microsoft.Resources/deployments*"}).TargetResource
}
@Selena20191
Copy link

[]() #

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