How to remove a batch of VMs and related Disks
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
- 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
- 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
- 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的更多相关文章
- 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 ...
- docker学习(1) 安装
docker是啥就不多讲了,简言之就是更轻量.更牛叉的新一代虚拟机技术.下面是安装步骤: 一.mac/windows平台的安装 docker是在linux内核基础上发展而来的,无法直接运行在mac/w ...
- 如何批量删除虚拟机及其关联的存储(Windows Azure)
可以通过运行附件中PowerShell脚本文件RemoveVMandDisk.ps1批量删除VM和Disk,详细代码如下: param($serviceName) echo "Startin ...
- 大规模视觉识别挑战赛ILSVRC2015各团队结果和方法 Large Scale Visual Recognition Challenge 2015
Large Scale Visual Recognition Challenge 2015 (ILSVRC2015) Legend: Yellow background = winner in thi ...
- Spark小课堂Week6 启动日志详解
Spark小课堂Week6 启动日志详解 作为分布式系统,Spark程序是非常难以使用传统方法来进行调试的,所以我们主要的武器是日志,今天会对启动日志进行一下详解. 日志详解 今天主要遍历下Strea ...
- Spark Streaming揭秘 Day28 在集成开发环境中详解Spark Streaming的运行日志内幕
Spark Streaming揭秘 Day28 在集成开发环境中详解Spark Streaming的运行日志内幕 今天会逐行解析一下SparkStreaming运行的日志,运行的是WordCountO ...
- ovirt user guide
Contents [hide] 1 Accessing the User Portal 1.1 Logging in to the User Portal 1.2 Logging out of t ...
- Local模式下Spark程序只输出关键信息
使用spark-submit提交local任务时,会输出很多Info信息: ------------------------------------------- Time: ms --------- ...
- spark stream001
package stream.scala import java.io.PrintWriter import java.net.ServerSocket class LoggerSimulation ...
随机推荐
- OpenResty(nginx+lua) 入门
OpenResty 官网:http://openresty.org/ OpenResty 是一个nginx和它的各种三方模块的一个打包而成的软件平台.最重要的一点是它将lua/luajit打包了进来, ...
- HTTP状态码206和416
HTTP 2xx范围内的状态码表明了:"客户端发送的请求已经被服务器接受并且被成功处理了". TTP/1.1 200 OK是HTTP请求成功后的标准响应 HTTP/1.1 206状 ...
- [整]SQL执行顺序
SQL的执行顺序: 第一步:FROM <left_table> <join_type> JOIN <right_table> ON <on_predicate ...
- [转]Shell中read的常用方式
原文:Linux Shell Scripting Tutorial V2.0 read命令的语法: read -p "Prompt" variable1 variable2 var ...
- 关于/etc/rc.local以及/etc/init.d
1. /etc/rc.local 这是使用者自订开机启动程序,把需要开机自动运行的程序写在这个脚本里 --------引用---------------------- 在完成 run le ...
- Kali Linux 秘籍/Web渗透秘籍/无线渗透入门
Kali Linux 秘籍 原书:Kali Linux Cookbook 译者:飞龙 在线阅读 PDF格式 EPUB格式 MOBI格式 Github Git@OSC 目录: 第一章 安装和启动Kali ...
- 让HTML页面缩放适应移动客户端尺寸
多的不说了,直接看代码吧 <html lang="en"> <head> <meta http-equiv = "X-UA-Compatib ...
- TeamTalk源码分析之服务端描述
TTServer(TeamTalk服务器端)主要包含了以下几种服务器: LoginServer (C++): 登录服务器,分配一个负载小的MsgServer给客户端使用 MsgServer (C++) ...
- UART to Serial Terminal(转载)
前一篇<UART Explained>介绍了UART的基本信息,重点分析了UART的信号.本文摘录的文章则重点介绍了波特率(Baud Rate)相关的内容,波特率越高,传输速度越快,但实际 ...
- HDU4003Find Metal Mineral[树形DP 分组背包]
Find Metal Mineral Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Other ...