Skip to content

Instantly share code, notes, and snippets.

Embed
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: https://docs.microsoft.com/en-us/powershell/azure/install-az-ps?view=azps-1.0.0
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
#>
Param(
[GUID][Parameter(Mandatory=$true)]$guid,
[string][Parameter(Mandatory=$true)]$resourceGroupName
)
#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{$_.properties.provisioningOperation -eq "Create" -and $_.properties.targetResource.resourceType -ne "Microsoft.Resources/deployments"}).properties.targetResource.id
}
@yuishi-ms

This comment has been minimized.

Copy link

@yuishi-ms yuishi-ms commented Jan 19, 2021

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