You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm pasting a script that will work for azure government users that have problems removing the artifacts that the main branch removes for azure commercial. The main changes are the Addition of the -environment variable to the Login line and the removal of the unnecessary host component of the URL in the LinkResourceId variable.
cls
$subscriptionId = Read-Host 'What is your Azure Subscription ID?'
$rgName = Read-Host 'Specify the name of the Resource group in which your VM is located'
$vmName = Read-Host 'Specify the name of the VM'
# Sign-in with Azure account credentials
Login-AzureRmAccount -Environment AzureUSGovernment
# Select Azure Subscription
Select-AzureRmSubscription -SubscriptionId $subscriptionId
# Remove any locks t
$locks = Get-AzureRmResourceLock -ResourceGroupName $rgName -ResourceName $vmName -ResourceType Microsoft.Compute/virtualMachines
if ($locks -ne $null -and $locks.Count -ge 0){
$canDelete = Read-Host 'The VM has locks that could prevent cleanup of Azure Site Recovery stale links left from previous protection. Do you want the locks deleted to ensure cleanup goes smoothly? Reply with Y/N.'
if ($canDelete.ToLower() -eq "y"){
Foreach ($lock in $locks) {
$lockId = $lock.LockId
Remove-AzureRmResourceLock -LockId $lockId -Force
Write-Host "Removed Lock $lockId for $vmName"
}
}
}
$linksResourceId = '/subscriptions/' + $subscriptionId + '/providers/Microsoft.Resources/links'
$vmId = '/subscriptions/' + $subscriptionId + '/resourceGroups/' + $rgName + '/providers/Microsoft.Compute/virtualMachines/' + $vmName + '/'
Write-Host $("Deleting links for $vmId using resourceId: $linksResourceId")
$links = @(Get-AzureRmResource -ResourceId $linksResourceId| Where-Object {$_.Properties.sourceId -match $vmId -and $_.Properties.targetId.ToLower().Contains("microsoft.recoveryservices/vaults")})
Write-Host "Links to be deleted"
$links
#Delete all links which are of type
Foreach ($link in $links)
{
Write-Host $("Deleting link " + $link.Name)
Remove-AzureRmResource -ResourceId $link.ResourceId -Force
}
$links = @(Get-AzureRmResource -ResourceId $linksResourceId| Where-Object {$_.Properties.sourceId -match $vmId -and $_.Properties.targetId.ToLower().Contains("/protecteditemarmid/")})
Write-Host "Cross subscription Links to be deleted"
$links
#Delete all links which are of type
Foreach ($link in $links)
{
Write-Host $("Deleting link " + $link.Name)
Remove-AzureRmResource -ResourceId $link.ResourceId -Force
}
Write-Host $("Deleted all links ")
The text was updated successfully, but these errors were encountered:
I'm pasting a script that will work for azure government users that have problems removing the artifacts that the main branch removes for azure commercial. The main changes are the Addition of the -environment variable to the Login line and the removal of the unnecessary host component of the URL in the LinkResourceId variable.
The text was updated successfully, but these errors were encountered: