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 ...
随机推荐
- iNeedle日志下载功能问题
问题: iNeedle系统本身包含日志下载功能,主要是将web服务器中的用户访问日志按照一定条件进行筛选并下载,提供管理者分析.但是这次的测试中发现iNeedle日志下载一直会卡住,web界面显示正在 ...
- android Timer使用方法
Timer属性:http://www.apihome.cn/api/java/Timer.html 声明创建: private Timer mTimer; protected void onCreat ...
- Android 项目中文件夹的说明与作用(转)
(转自:http://blog.csdn.net/goodshot/article/details/11529731) Android 项目中文件夹的作用 1. src:存放所有的*.java源程序. ...
- Linux vim编辑命令
yum install -y vim-enhanced 安装vim 命令 一般模式 shift 4 行尾 shift 6 或 0行首 gg 顶部 G 下部 复制 yy 剪切几行 数字 dd p粘贴 ...
- Windows Azure文件共享服务--File Service
部署在Windows Azure上的虚拟机之间如何共享文件?例如:Web Server A和Web Server B组成负载均衡集群,两个服务器需要一个共享目录来存储用户上传的文件.通常,大家可能首先 ...
- [转]ng-grid
本文转自:http://angular-ui.github.io/ui-grid/ Getting Started Steps for getting started (example on righ ...
- system generator 卷积编码器快速设计
卷积码 卷积码是一种特殊的编码方式,不仅与当前的输入有关,还与之前的输入有关.可以用一个多项式来表示一个卷积编码,多项式表示有多少个移位寄存器以及他们怎么与模2加法器相连.比如,下图中的无反馈的卷积编 ...
- 如何用ZBrush做人体造型雕刻
之前我们用ZBrush®中的Curves和Insert笔刷快速创建模型的躯干.四肢以及手指.经过老师耐心的讲解我们也收获了很多,知道了创建模型的流程和雕刻技巧.今天的ZBrush教程将结合一些新的雕刻 ...
- windows 7 语言切换 Vistalizator
Try Vistalizator - this tool allows you to change display language in Windows editions other than (o ...
- POJ 3449 Geometric Shapes --计算几何,线段相交
题意: 给一些多边形或线段,输出与每一个多边形或线段的有哪一些多边形或线段. 解法: 想法不难,直接暴力将所有的图形处理成线段,然后暴力枚举,相交就加入其vector就行了.主要是代码有点麻烦,一步一 ...