Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1172581
  • 博文数量: 150
  • 博客积分: 2739
  • 博客等级: 少校
  • 技术积分: 2392
  • 用 户 组: 普通用户
  • 注册时间: 2010-12-07 12:28
文章分类

全部博文(150)

文章存档

2015年(2)

2014年(16)

2013年(10)

2012年(58)

2011年(64)

分类: PERL

2014-05-08 11:44:15


     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 

点击(此处)折叠或打开

  1. param($serviceName)
  2. echo "Starting remove all vms of service $serviceName"
  3. #$serviceName="gasfef"
  4. echo "Get all DiskNames of all VMs of service $serviceName."
  5. $azureDiskNames= Get-AzureDisk| where{$_.AttachedTo -ne $null -and $_.AttachedTo.HostedServicename.StartsWith($serviceName)} | select DiskName
  6. $azureDiskNames
  7. if($azureDiskNames -eq $null -or $azureDiskNames.Count -eq 0){
  8. echo "No VMs wanted to Remove."
  9. exit
  10. }
  11. echo "`r`nStarting remove all VMs of service $serviceName..."
  12. Get-AzureVM | where{$_.ServiceName.StartsWith($serviceName)} | Remove-AzureVM -Verbose
  13. #It spends time to remove VM on backend.
  14. echo "Waiting Removing VM on backend..."
  15. Start-Sleep -Seconds 120 $azureDiskNames.Count
  16. echo "`r`nStarting remove all related disks..."
  17. foreach($diskName in $azureDiskNames){
  18. Get-AzureDisk | where {$_.DiskName -eq $diskName.DiskName } | Remove-AzureDisk -DeleteVHD -Verbose
  19. }
  20. echo "`r`nStarting remove all services"
  21. Get-AzureService | where{$_.ServiceName.StartsWith($serviceName)} | Remove-AzureService -Force -Verbose

  22. echo "`r`Starting remove all StorageAccountName"
  23. Get-AzureStorageAccount |select StorageAccountName | Remove-AzureStorageAccount -Verbose


阅读(5022) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~