diff --git a/utilities/pipelines/resourceRemoval/helper/Invoke-ResourcePostRemoval.ps1 b/utilities/pipelines/resourceRemoval/helper/Invoke-ResourcePostRemoval.ps1 index 54a48513f7..d158ba6b94 100644 --- a/utilities/pipelines/resourceRemoval/helper/Invoke-ResourcePostRemoval.ps1 +++ b/utilities/pipelines/resourceRemoval/helper/Invoke-ResourcePostRemoval.ps1 @@ -113,30 +113,6 @@ function Invoke-ResourcePostRemoval { } break } - 'Microsoft.OperationalInsights/workspaces' { - $subscriptionId = $resourceId.Split('/')[2] - $resourceGroupName = $resourceId.Split('/')[4] - $resourceName = Split-Path $ResourceId -Leaf - # Fetch service in soft-delete state - $getPath = '/subscriptions/{0}/providers/Microsoft.OperationalInsights/deletedWorkspaces?api-version=2020-03-01-preview' -f $subscriptionId - $getRequestInputObject = @{ - Method = 'GET' - Path = $getPath - } - $softDeletedService = ((Invoke-AzRestMethod @getRequestInputObject).Content | ConvertFrom-Json).value | Where-Object { $_.id -eq $resourceId -and $_.name -eq $resourceName } - if ($softDeletedService) { - # Recover service - $location = $softDeletedService.location - if ($PSCmdlet.ShouldProcess(('Log analytics workspace [{0}]' -f $resourceId), 'Recover')) { - $recoveredWorkspace = New-AzOperationalInsightsWorkspace -ResourceGroupName $resourceGroupName -Name $resourceName -Location $location - } - # Purge service - if ($PSCmdlet.ShouldProcess(('Log analytics workspace with ID [{0}]' -f $resourceId), 'Purge')) { - $recoveredWorkspace | Remove-AzOperationalInsightsWorkspace -ForceDelete -Force - } - } - break - } 'Microsoft.RecoveryServices/vaults/backupFabrics/protectionContainers/protectedItems' { # Remove protected VM # Required if e.g. a VM was listed in an RSV and only that VM is removed diff --git a/utilities/pipelines/resourceRemoval/helper/Invoke-ResourceRemoval.ps1 b/utilities/pipelines/resourceRemoval/helper/Invoke-ResourceRemoval.ps1 index a6325482c3..c6e93e3efa 100644 --- a/utilities/pipelines/resourceRemoval/helper/Invoke-ResourceRemoval.ps1 +++ b/utilities/pipelines/resourceRemoval/helper/Invoke-ResourceRemoval.ps1 @@ -126,6 +126,16 @@ function Invoke-ResourceRemoval { $null = Remove-AzResource -ResourceId $resourceId -Force -ErrorAction 'Stop' break } + 'Microsoft.OperationalInsights/workspaces' { + $resourceGroupName = $resourceId.Split('/')[4] + $resourceName = Split-Path $resourceId -Leaf + # Force delete workspace (cannot be recovered) + if ($PSCmdlet.ShouldProcess("Log Analytics Workspace [$resourceName]", 'Remove')) { + $null = Remove-AzOperationalInsightsWorkspace -ResourceGroupName $resourceGroupName -Name $resourceName -Force -ForceDelete + } + break + } + ### CODE LOCATION: Add custom removal action here Default { $null = Remove-AzResource -ResourceId $resourceId -Force -ErrorAction 'Stop'