Skip to content

Commit

Permalink
Update Remove-AzrVirtualMachine
Browse files Browse the repository at this point in the history
Boot Diagnostics Container Name formula now takes into account VM names with special characters like '-' or '_' and removes them before "guessing" the name of the container.
Azure automatically removes these when naming the Boot Diagnostics Container.
  • Loading branch information
DanteNahuel authored Mar 4, 2020
1 parent 7f43cd9 commit 2d9b36b
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Azure/Remove-AzrVirtualMachine.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ function Remove-AzrVirtualMachine {
$vmResource = Get-AzResource @azResourceParams
$vmId = $vmResource.Properties.VmId
#endregion

$diagContainerName = ('bootdiagnostics-{0}-{1}' -f $vm.Name.ToLower().Substring(0, $i), $vmId)
$vmnameNoSpecialCharacters = $vm.name -replace '[^\p{L}\p{Nd}]', ''
$diagContainerName = ('bootdiagnostics-{0}-{1}' -f $vmnameNoSpecialCharacters.ToLower().Substring(0, $i), $vmId)
$diagSaRg = (Get-AzStorageAccount | where { $_.StorageAccountName -eq $diagSa }).ResourceGroupName
$saParams = @{
'ResourceGroupName' = $diagSaRg
Expand Down Expand Up @@ -140,4 +140,4 @@ function Remove-AzrVirtualMachine {
Start-Job @jobParams
}
}
}
}

0 comments on commit 2d9b36b

Please sign in to comment.