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
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
}
@SKenniston

This comment has been minimized.

Copy link

@SKenniston SKenniston commented Nov 15, 2018

Newbie here! When using the Select-AzureRMContext - what is the value of "InputObject"?

@stuartleeks

This comment has been minimized.

Copy link

@stuartleeks stuartleeks commented Jan 16, 2019

For anyone using the new Az PowerShell module, I have a fork of this script that I converted to the new cmdlets (which seems to work based on my extremely limited testing!)

@bmoore-msft

This comment has been minimized.

Copy link
Owner Author

@bmoore-msft bmoore-msft commented Feb 16, 2021

Updated for the breaking change in the Az 5.0 cmdlets (also limited testing ;))

@jardiacaj

This comment has been minimized.

Copy link

@jardiacaj jardiacaj commented Jun 9, 2021

Is there also an option to verify the GUID for resources created with Terraform?

@bmoore-msft

This comment has been minimized.

Copy link
Owner Author

@bmoore-msft bmoore-msft commented Jun 9, 2021

If you deploy a template via TF yes, but if it's not a template deployment then no... that data is only available internally. You should be able to reach out to someone on the partner side to help though...

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