Windows Azure Powershell remove virtual machines and VHD
The scripts can remove virtual machines and cloud server and VHD, but can't remove storage account
点击(此处)折叠或打开
- param($serviceName)
- echo "Starting remove all vms of service $serviceName"
- #$serviceName="gasfef"
- echo "Get all DiskNames of all VMs of service $serviceName."
- $azureDiskNames= Get-AzureDisk| where{$_.AttachedTo -ne $null -and $_.AttachedTo.HostedServicename.StartsWith($serviceName)} | select DiskName
- $azureDiskNames
- if($azureDiskNames -eq $null -or $azureDiskNames.Count -eq 0){
- echo "No VMs wanted to Remove."
- exit
- }
- echo "`r`nStarting remove all VMs of service $serviceName..."
- Get-AzureVM | where{$_.ServiceName.StartsWith($serviceName)} | Remove-AzureVM -Verbose
- #It spends time to remove VM on backend.
- echo "Waiting Removing VM on backend..."
- Start-Sleep -Seconds 120 $azureDiskNames.Count
- echo "`r`nStarting remove all related disks..."
- foreach($diskName in $azureDiskNames){
- Get-AzureDisk | where {$_.DiskName -eq $diskName.DiskName } | Remove-AzureDisk -DeleteVHD -Verbose
- }
- echo "`r`nStarting remove all services"
- Get-AzureService | where{$_.ServiceName.StartsWith($serviceName)} | Remove-AzureService -Force -Verbose
- echo "`r`Starting remove all StorageAccountName"
- Get-AzureStorageAccount |select StorageAccountName | Remove-AzureStorageAccount -Verbose