惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Threat Research - Cisco Blogs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
V
Vulnerabilities – Threatpost
GbyAI
GbyAI
P
Proofpoint News Feed
L
LINUX DO - 热门话题
P
Palo Alto Networks Blog
A
About on SuperTechFans
T
Tenable Blog
M
MIT News - Artificial intelligence
IT之家
IT之家
I
Intezer
D
DataBreaches.Net
爱范儿
爱范儿
T
Threatpost
C
CERT Recently Published Vulnerability Notes
云风的 BLOG
云风的 BLOG
博客园 - 三生石上(FineUI控件)
WordPress大学
WordPress大学
K
Kaspersky official blog
大猫的无限游戏
大猫的无限游戏
A
Arctic Wolf
Y
Y Combinator Blog
Cyberwarzone
Cyberwarzone
酷 壳 – CoolShell
酷 壳 – CoolShell
D
Darknet – Hacking Tools, Hacker News & Cyber Security
H
Help Net Security
Microsoft Security Blog
Microsoft Security Blog
Spread Privacy
Spread Privacy
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
AWS News Blog
AWS News Blog
博客园 - 聂微东
C
Check Point Blog
S
Securelist
有赞技术团队
有赞技术团队
雷峰网
雷峰网
aimingoo的专栏
aimingoo的专栏
Last Week in AI
Last Week in AI
Stack Overflow Blog
Stack Overflow Blog
MongoDB | Blog
MongoDB | Blog
D
Docker
G
GRAHAM CLULEY
T
The Exploit Database - CXSecurity.com
C
Cybersecurity and Infrastructure Security Agency CISA
T
Tailwind CSS Blog
L
Lohrmann on Cybersecurity
G
Google Developers Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
L
LangChain Blog

博客园 - EricWen

IntelliJ IDEA 2024 安装与激活全攻略 Excel高手秘籍:50招助你效率翻倍 Navicat与DBeaver:数据库管理工具界的“蝙蝠侠”与“钢铁侠” 十年沉淀,重启开发之路 外网不能访问部署在虚机的NodeJs网站(80端口) Common Issues Which Cause Roles to Recycle How to remove a batch of VMs and related Disks How to create a batch of VMs with PowerShell How to build windows azure PowerShell Source Code 如何快速从一个Storage Account拷贝到另一个账号 比较Windows Azure 网站(Web Sites), 云服务(Cloud Services)and 虚机(Virtual Machines) Windows Azure 云服务角色架构 PowerShell Script to Deploy Multiple VM on Azure in Parallel #azure #powershell Use Windows Azure AD to create SSO projects 怎样提高Windows Azure Cloud Service中的WebRole的文件访问权限 Windows Azure 名词定义(Glossary) 怎样将SQL Azure数据库备份到本地或者Storage 自动备份SQL数据库到云存储Storage 数据库SQL Server DAC 导入导出数据到SQL Azure问题
如何批量删除虚拟机及其关联的存储(Windows Azure)
EricWen · 2014-02-24 · via 博客园 - EricWen

可以通过运行附件中PowerShell脚本文件RemoveVMandDisk.ps1批量删除VM和Disk,详细代码如下:

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. 打开Windows Azure PowerShell, 并导入订阅信息(Subscription)。

关于如何安装和配置Azure PowerShell,请参考http://www.windowsazure.com/en-us/documentation/articles/install-configure-powershell/

需要注意一点,在执行Get-AzurePublishSettingsFile命令获取Subscription文件的时候,不要使用它自动跳转的Url(这是国外Windows Azure的链接),需要手动输入https://manage.windowsazure.cn/publishsettings/index?client=powershell ,然后登录并获取Subscription文件

  1. 运行命令 Set-ExecutionPolicy RemoteSigned 更执行策略。
  2. 执行RemoveVMandDisk.ps1脚本。

语法:RemoveVMandDisk.ps1 <ServiceName> #可以删除以这个ServiceName开头的所有虚机VM

例子:RemoveVMandDisk.ps1 ericwenService

如果您在删除虚机后,删除Disk发生错误“当前磁盘被占用”,可以修改等待后台运行时间:Start-Sleep -Seconds 120* $azureDiskNames.Count

  1. 您还可以使用命令(Get-AzureDisk| where{ $_.AttachedTo -eq $null } | Remove-AzureDisk -DeleteVHD -Verbose )删除所有未使用(附加到VM上)的磁盘

以上脚本和代码仅供参考,您可以根据您的业务逻辑做调整和修改。