Skip to content

Instantly share code, notes, and snippets.

@bmoore-msft
Last active June 7, 2024 09:34
Show Gist options
  • Select an option

  • Save bmoore-msft/ae6b8226311014d6e7177c5127c7eba1 to your computer and use it in GitHub Desktop.

Select an option

Save bmoore-msft/ae6b8226311014d6e7177c5127c7eba1 to your computer and use it in GitHub Desktop.

Revisions

  1. bmoore-msft revised this gist Feb 16, 2021. 1 changed file with 10 additions and 16 deletions.
    26 changes: 10 additions & 16 deletions Verify-DeploymentGuid.ps1
    Original file line number Diff line number Diff line change
    @@ -1,24 +1,18 @@
    <#
    Use this script to retrieve the resources that were deployed with a pid-[GUID] tag
    Select-AzureRMContext 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)]$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 pid deployment
    $correlationId = (Get-AzureRmResourceGroupDeployment -ResourceGroupName $resourceGroupName -Name "pid-$guid").correlationId

    #find all deployments with that correlationId
    $deployments = Get-AzureRmResourceGroupDeployment -ResourceGroupName $resourceGroupName | Where-Object{$_.correlationId -eq $correlationId}
    # Get the correlationId of the named deployment
    $correlationId = (Get-AzResourceGroupDeployment -ResourceGroupName $resourceGroupName -Name "$deploymentName").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){
    # Find all deployments with that correlationId
    $deployments = Get-AzResourceGroupDeployment -ResourceGroupName $resourceGroupName | Where-Object{$_.correlationId -eq $correlationId}

    #get deploymentOperations by deploymentName and then the resourceId for any create operation
    ($deployment | Get-AzureRmResourceGroupDeploymentOperation | Where-Object{$_.properties.provisioningOperation -eq "Create" -and $_.properties.targetResource.resourceType -ne "Microsoft.Resources/deployments"}).properties.targetResource.id
    # 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
    }
  2. bmoore-msft revised this gist Oct 3, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Verify-DeploymentGuid.ps1
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,7 @@

    Param(
    [GUID][Parameter(Mandatory=$true)]$guid,
    [string][Parameter(Mandatory=$true)]$resourceGroupName'
    [string][Parameter(Mandatory=$true)]$resourceGroupName
    )

    #get the correlationId of the pid deployment
  3. bmoore-msft created this gist Jun 13, 2018.
    24 changes: 24 additions & 0 deletions Verify-DeploymentGuid.ps1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    <#
    Use this script to retrieve the resources that were deployed with a pid-[GUID] tag
    Select-AzureRMContext 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-AzureRmResourceGroupDeployment -ResourceGroupName $resourceGroupName -Name "pid-$guid").correlationId
    #find all deployments with that correlationId
    $deployments = Get-AzureRmResourceGroupDeployment -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-AzureRmResourceGroupDeploymentOperation | Where-Object{$_.properties.provisioningOperation -eq "Create" -and $_.properties.targetResource.resourceType -ne "Microsoft.Resources/deployments"}).properties.targetResource.id
    }