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. mydumper 安装报错处理

    mydumper 官网:https://launchpad.net/mydumper 下载之后,安装报错: [root@localhost local]# cd mydumper-0.6.2 [roo ...

  2. 关于《Windows程序设计(第五版)》中一个实例程序的疑问

    最近一直在看Charlse Petzold的<Windows程序设计>,作为一个新得不能再新的新手,只能先照着书的抄抄源码了,之前的例子一直都很正常,但昨天遇到一个很诡异的BUG. 先看实 ...

  3. 【转】Linux Mint 17.2 gedit中文乱码

    转自:linux mint 14 gedit 中文乱码 Mint默认没安装gconf-editor,搜了下,找到如下解决办法 在终端下执行语句: gconftool- --set --type=lis ...

  4. Java:JSTL遍历数组,List,Set,Map

    <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...

  5. Floyd算法解决多源最短路径问题

    Floyd-Warshall算法是解决任意两点间的最短路径的一种算法,可以正确处理有向图或负权(但不可存在负权回路)的最短路径问题,同时也被用于计算有向图的传递闭包. Floyd-Warshall算法 ...

  6. Machine Learning Algorithms Study Notes(4)—无监督学习(unsupervised learning)

    1    Unsupervised Learning 1.1    k-means clustering algorithm 1.1.1    算法思想 1.1.2    k-means的不足之处 1 ...

  7. (五)适配器模式-C++实现

    将一个类的接口转换成客户希望的另外一个接口.Adapter模式使得原本由于接口不兼容而不能一起工作的那些类可以一起工作. 该模式中有三种角色: 1.目标:是一个抽象类,它是客户想使用的接口 2.被适配 ...

  8. Unity Profiler 性能分析

    Profiler窗口 1. CPU A. WaitForTargetFPS:       Vsync(垂直同步)功能所,即显示当前帧的CPU等待时间    B. Overhead:       Pro ...

  9. Beanstalk消息队列的实现

    在工作中要用到消息队列,但是主管为了追求开发速度,让用了一个简易的类  beanstalk 下面来说明这个东西 参考博客:https://my.oschina.net/u/698121/blog/15 ...

  10. 怎样关闭WIN7系统的自动更新

    百度经验 > 游戏/数码 > 电脑 > 电脑软件 怎样关闭WIN7系统的自动更新 听语音 | 浏览:108460 | 更新:2012-07-24 18:03 | 标签:win7 1 ...