Last active
August 28, 2018 19:02
-
-
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
This file contains hidden or 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
# 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