Foreword

Need to remove a batch of VMs, which named with same prefix or belong to same Cloud Service. After remove VMs, should automatically remove related disk (OS disk & Data Disk) and related VHD file .

Keywords

PowerShell Get-AzureVM Remove-AzureVM

Summary

Write and run Windows Azure PowerShell script to implement this feature.

Detailed

  1. The PowerShell script is below.

param($serviceName)

echo "Starting remove all vms of service $serviceName"

#$serviceName="erictest"

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 -le 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

  1. If want to remove all Disks not attached to any VM, can use one CmdLet : Get-AzureDisk| where{ $_.AttachedTo -eq $null } | Remove-AzureDisk -DeleteVHD -Verbose
  2. If want to create a batch of VMs with one data disk attached. How to create a batch of VMs with PowerShell

Conclusion

Reference

How to remove a batch of VMs and related Disks的更多相关文章

  1. How to create a batch of VMs with PowerShell

    Foreword When we do some test that need several VMs, we can use PowerShell script or CmdLets to impl ...

  2. docker学习(1) 安装

    docker是啥就不多讲了,简言之就是更轻量.更牛叉的新一代虚拟机技术.下面是安装步骤: 一.mac/windows平台的安装 docker是在linux内核基础上发展而来的,无法直接运行在mac/w ...

  3. 如何批量删除虚拟机及其关联的存储(Windows Azure)

    可以通过运行附件中PowerShell脚本文件RemoveVMandDisk.ps1批量删除VM和Disk,详细代码如下: param($serviceName) echo "Startin ...

  4. 大规模视觉识别挑战赛ILSVRC2015各团队结果和方法 Large Scale Visual Recognition Challenge 2015

    Large Scale Visual Recognition Challenge 2015 (ILSVRC2015) Legend: Yellow background = winner in thi ...

  5. Spark小课堂Week6 启动日志详解

    Spark小课堂Week6 启动日志详解 作为分布式系统,Spark程序是非常难以使用传统方法来进行调试的,所以我们主要的武器是日志,今天会对启动日志进行一下详解. 日志详解 今天主要遍历下Strea ...

  6. Spark Streaming揭秘 Day28 在集成开发环境中详解Spark Streaming的运行日志内幕

    Spark Streaming揭秘 Day28 在集成开发环境中详解Spark Streaming的运行日志内幕 今天会逐行解析一下SparkStreaming运行的日志,运行的是WordCountO ...

  7. ovirt user guide

    Contents [hide]  1 ⁠Accessing the User Portal 1.1 Logging in to the User Portal 1.2 Logging out of t ...

  8. Local模式下Spark程序只输出关键信息

    使用spark-submit提交local任务时,会输出很多Info信息: ------------------------------------------- Time: ms --------- ...

  9. spark stream001

    package stream.scala import java.io.PrintWriter import java.net.ServerSocket class LoggerSimulation ...

随机推荐

  1. 对最近的RTP和H264学习进行总结整理-04.20

    虽然还是没有搞出来,但总感觉快了哈哈(哪来的自信) 1.RTP协议接受数据 #region 1-RTP协议变量声明 RTPSession session; RTPReceiver receiver; ...

  2. iOS Build Active Architecture Only 属性的理解(及 not found for architecture i386 的解决方案)

    最近做项目过程遇到一个问题: 涉及到这个属性:Build Active Architecture Only Yes .No的区别: 设置为yes,是只编译当前的architecture版本,是为了编译 ...

  3. LINUX内核笔记:自旋锁

    目录 自旋锁作用与基本使用方法? 在SMP和UP上的不同表现? 自旋锁与上下文 使用spin_lock()后为什么不能睡眠? 强调:锁什么? 参考   1.自旋锁作用与基本使用方法? 与其他锁一样,自 ...

  4. Android程序函数 将assets文件夹下的文件复制到手机的sd卡中(包括子文件夹)

    最近在做个功能是将asset文件夹下的所有文件(包括子文件)全部拷贝出来到指定目录下.所用的方法无非是用AssetManager.但是这里 有个问题是也要讲子文件夹和子文件都要拷贝出来.到网上Goog ...

  5. SQLITE配置环境变量

      SQLITE配置环境变量和Java的配置其实是一样的,不过好像每个人配的时候不完全相同, 有的机器可以,另外一些机器同样的方法却行不通,总之思路是一样的多试几种,总有合适的参数 下面是我在配置时截 ...

  6. java的访问权限

    Java语言中有4中访问修饰符:friendly(默认).private.public和protected. public :能被所有的类(接口.成员)访问. protected:只能被本类.同一个包 ...

  7. python 笔记(一) —— 不要误用 ++i、--i

    ilocker:关注 Android 安全(新手) QQ: 2597294287 在 python 中也可以写 ++i,但含义完全不同于 c/c++.python 的 ++i 并不是将 i 自增 1, ...

  8. MS SQLServer 操作XML语句的存储过程

    -- ================================================ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ...

  9. 移动前端UI选择

    移动前端UI选择 目录 三.SUI Mobile   一.jQuery Mobile jQuery Mobile 是jQuery在移动设备上的版本,做为主要针对移动设备的框架来说,它提供一个移动设备平 ...

  10. Flex数据绑定陷阱(一)

    Flex数据绑定陷阱:常见的误用和错误 当构建Flex或者Adobe AIR程序时,将一个对象的值自动的传递给另一个对象这种处理是数据绑定最常 用并最有用的特征之一. 尽管如此,同时数据绑定会减缓程序 ...