Forked from bmoore-msft/Verify-DeploymentGuid.ps1
Last active
January 19, 2021 10:13
-
-
Save stuartleeks/ed84b0cc242b0abed85a9aea0b032fc3 to your computer and use it in GitHub Desktop.
Fetch the resources tagged in a pid-[GUID] deployment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
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 | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.