Skip to content

Instantly share code, notes, and snippets.

@martin77s
Last active August 28, 2018 19:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martin77s/ac350f2c6183de70ace57ac7b93ed482 to your computer and use it in GitHub Desktop.
Save martin77s/ac350f2c6183de70ace57ac7b93ed482 to your computer and use it in GitHub Desktop.
Select and remove Azure Hybrid Connection objects from all namespaces in all resource groups
# Login to Azure
Login-AzureRmAccount
# Select a specific subscription for the context
Get-AzureRmSubscription | Out-GridView -PassThru -Title 'Select Subscription' | Select-AzureRmSubscription
# Get all the Hybrid Connections from all namespaces in all resource groups
$hybridConnections = Get-AzureRmResource -ResourceType Microsoft.Relay/namespaces | ForEach-Object {
$resourceGroupName = $_.ResourceGroupName
Get-AzureRmRelayHybridConnection -ResourceGroupName $resourceGroupName -Namespace $namespace.Name | ForEach-Object {
$resourceName = '{0}/{1}' -f ($_.Id -split '/')[-3,-1]
Get-AzureRmResource -ResourceGroupName $resourceGroupName -ResourceType Microsoft.Relay/Namespaces/HybridConnections `
-ApiVersion 2016-07-01 -ResourceName $resourceName | Select-Object @{N='ResourceGroupName';E={$resourceGroupName}},
@{N='ResourceName';E={$resourceName}},
@{N='CreatedAt';E={$_.Properties.createdAt}},
@{N='UpdatedAt';E={$_.Properties.updatedAt}},
@{N='ListenerCount';E={$_.Properties.listenerCount}},
@{N='UserMetadata';E={$_.Properties.userMetadata}}
}
}
# Ask which connection to delete
$hybridConnections | Out-GridView -PassThru -Title 'Select the Hybrid Connections you want to delete' | ForEach-Object {
Remove-AzureRmResource -ResourceGroupName $resourceGroupName -ResourceType Microsoft.Relay/Namespaces/HybridConnections `
-ApiVersion 2016-07-01 -ResourceName $_.ResourceName -Force
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment