Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down