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. Linux文件I/O

    文件描述符(File Descriptor) a small, nonnegative integer for use in subsequent system calls (read(2), wri ...

  2. x01.BitmapHelper:图像处理

    “所有致我于死地的,也激发我胆魄”,姚贝娜的<心火>,是我近年来听过最好的歌,特此推荐一下. 图像处理,大概分三步:1.LockBits():2.进行处理:3.UnlockBits():这 ...

  3. adroid 目录

    安桌程式安装后存在目录:\手机存储\Android\data 一: //  获取当前程序路径 getApplicationContext().getFilesDir().getAbsolutePath ...

  4. 如何生成可变表头的excel

    1.实现功能: 传入一个表头和数据,将数据导入到excel中. 为了便于项目的扩展,数据传入通过泛型集合传入,获取数据时,通过反射的方式获取,这样无论你的表头是多少项,我都能很方便的生成.另外为了便于 ...

  5. 六轴加速度传感器MPU6050官方DMP库到瑞萨RL78/G13的移植

    2015年的电赛已经结束了.赛前接到器件清单的时候,看到带防护圈的多旋翼飞行器赫然在列,又给了一个瑞萨RL78/G13的MCU,于是自然联想到13年的电赛,觉得多半是拿RL78/G13做四旋翼的主控, ...

  6. Objective-C声明在头文件和实现文件中的区别

    Objective-C声明在头文件和实现文件中的区别 转自codecloud(有整理) 调试程序的时候,突然想到这个问题,百度一下发现有不少这方面的问答,粗略总结一下: 属性写在.h文件中和在.m文件 ...

  7. Interceptor

    拦截器是可以控制权限,当用户需要查看查看某些功能的时候,需要判断是不是登录了,如果没有登录的,就可拦截的过程.. 首先,我们都知道struts.xml 中有action 节点, 这个节点表示你想要访问 ...

  8. 这段时间对c#和java的感受

    这段时间对c#和java的感受 虽然很多书上说语法相似,但实际这是一个接近于门外汉的看法 真正的不同是 c#对更贴近系统API,      而java倡导跨平台 因而c#语法关键字更多,更细, 而ja ...

  9. Diffuse_Shader笔记1.shader和编辑器的交互

    1.写在前面的心情 o(︶︿︶)o   坚持不下来就是失败:每次看到candycat博客都会一阵阵冷汗很愧疚... shader .图形还是要学:不仅是兴趣,以后一定有用.现在做游戏UI开发,工作上还 ...

  10. TestLink学习二:Windows搭建TestLink环境

    环境准备: 搭建php5.4.39+apache2.2+mysq5.5.28l环境 (可参考http://www.cnblogs.com/yangxia-test/p/4414161.html) (注 ...