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

  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

时间: 2024-10-12 07:29:05

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

ovirt user guide

Contents [hide] 1 ?Accessing the User Portal 1.1 Logging in to the User Portal 1.2 Logging out of the User Portal 1.3 Logging in for the First Time: Installing the Engine Certificate 1.3.1 Installing oVirt Certificate in Firefox 2 ?Installing Support

<Spark><Spark Streaming><作业分析>

Intro 这篇是对一个Spark (Streaming)作业的log进行分析.用来加深对Spark application运行过程,优化空间的各种理解. Here to Start 从我这个初学者写得一个Spark Streaming程序开始... package com.wttttt.spark /** * Created with IntelliJ IDEA. * Description: * Author: wttttt * Github: https://github.com/wttt

Unreal Engine Plugin management

Be aware to remove any dependencies to any modules related to Editor, or else it will end up with failure of packaging. #if WITH_EDITOR #endif is your good friend. for developing purpose,  just copy plugins to developers' engine plugin folder for the

iOS各版本图标尺寸汇总

About Information Property List Files UILaunchImageFile UILaunchImageFile (String - iOS) specifies the name of the launch image file for the app on older versions of iOS. If this key and the UILaunchImages key are both present, the app uses the UILau

Expo大作战(二十七)--expo sdk api之Util(expo自带工具类),tackSnapshotAsync,Svg,SQLite

简要:本系列文章讲会对expo进行全面的介绍,本人从2017年6月份接触expo以来,对expo的研究断断续续,一路走来将近10个月,废话不多说,接下来你看到内容,讲全部来与官网 我猜去全部机翻+个人修改补充+demo测试的形式,对expo进行一次大补血!欢迎加入expo兴趣学习交流群:597732981 [之前我写过一些列关于expo和rn入门配置的东i西,大家可以点击这里查看:从零学习rn开发] 相关文章: Expo大作战(一)--什么是expo,如何安装expo clinet和xde,xd

Linux计划任务at&batch&crontab

计划任务        执行一次某任务:at,batch        周期性运行某任务:crontab    1.at命令,只执行一次 at/atq/atrm/batch    at [option]... time        HH:MM[YYYY-mm-dd] //        noon,midnight,teatime //12:00,24:00,16:00        tomorrow HH:MM         now+#            UNIT:minutest,ho

计划任务和周期任务mail,at,batch,atq, atrm, cron, crontab

Linux上的任务计划: 任务计划: 在未来时间点一次性执行某任务:at,batch 周期性执行某任务:crontab 电子邮件服务: 查看邮件服务是否启动:netstat -tlnup |grep "25" //25 port  smtpservice normal 默认收发邮件仅能在本机上的用户间进行,且只能通过回环接口上的地址进行 smtp:simple mail transmission protocol /var/spool/mail/USERNAME pop3: posto

Linux学习之计划任务(at、batch、vrontab)篇

Linux学习之任务计划(at.batch.vrontab)篇 一.linux上的任务计划 1.分类 linux上的任务计划可以分为两类: a.周期性执行的任务计划 crontab b.后续时间一次性执行的计划 at.batch 2.电子邮件服务 电子邮件服务使用到的几个协议: smtp:simple mail transmission protocol pop3:post office protocol imap4:internet mail access protocol 没个用户的都有一个

windows脚本-CMD和Batch

一.DOS,CMD和batch DOS是磁盘操作系统(英文:Disk Operating System)的缩写,是个人计算机上的一类操作系统.从1981年直到1995年的15年间,DOS在IBM PC兼容机市场中占有举足轻重的地位[1]. batch是DOS系统下的脚本,这些脚本是纯文本文档,以.bat为结尾,可以用任何文本编辑器来进行编辑.它的特点是文件的每一行都是当作命令来运行. CMD是用来运行batch的程序,在windows上是一个32位的命令行程序,基于windows操作系统的命令解