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 implement what we want.
Keywords
PowerShell, New-AzureVMConfig, New-AzureProvisioningConfig, New-AzureVM, Get-AzureVM, Add-AzureDataDisk, Update-AzureVM
Summary
Detailed
# Name of subscription
$SubscriptionName = "CIETest01"
# Name of storage account (where VMs will be deployed)
$StorageAccount = "portalvhdstpb7xn5sd8cck"
$VmNames=New-Object System.Collections.ArrayList
$VmNames.Add("erictest001")
$VmNames.Add("erictest002")
function Provision-VM( [string]$VmName ) {
Start-Job -ArgumentList $VmName {
param($VmName)
$Location = "China North"
$InstanceSize = "Small" # You can use any other instance, such as Large, A6, and so on
$AdminUsername = "ericwen" # Write the name of the administrator account in the new VM
$Password = "Passw0rd" # Write the password of the administrator account in the new VM
$Image = "0c5c79005aae478e8883bf950a861ce0__Windows-Server-2012-Essentials-20131018-enus" #Copy the ImageName property you get from Get-AzureVMImage
# You can list your own images using the following command:
# Get-AzureVMImage | Where-Object {$_.PublisherName -eq "User" }
New-AzureVMConfig -Name $VmName -ImageName $Image -InstanceSize $InstanceSize |
Add-AzureProvisioningConfig -Windows -Password $Password -AdminUsername $AdminUsername|
New-AzureVM -Location $Location -ServiceName "$VmName" -Verbose
}
}
# Set the proper storage - you might remove this line if you have only one storage in the subscription
Set-AzureSubscription -SubscriptionName $SubscriptionName -CurrentStorageAccount $StorageAccount
# Select the subscription - this line is fundamental if you have access to multiple subscription
# You might remove this line if you have only one subscription
Select-AzureSubscription -SubscriptionName $SubscriptionName
# Every line in the following list provisions one VM using the name specified in the argument
# You can change the number of lines - use a unique name for every VM - don't reuse names
# already used in other VMs already deployed
foreach($VmName in $VmNames)
{
Provision-VM $VmName
}
# Wait for all to complete
While (Get-Job -State "Running") {
Get-Job -State "Completed" | Receive-Job
Start-Sleep 1
}
# Display output from all jobs
Get-Job | Receive-Job
# Cleanup of jobs
Remove-Job *
# Displays batch completed
echo "Provisioning VM Completed"
echo "Attach new data disk to VM"
foreach($VmName in $VmNames){
Get-AzureVM -ServiceName $VmName -Name $VmName -Verbose | Add-AzureDataDisk -CreateNew -DiskSizeInGB 10 -DiskLabel "main" -LUN 1 -Verbose | Update-AzureVM -Verbose
}
Conclusion
Reference
How to create a batch of VMs with PowerShell的更多相关文章
- 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 ...
- Azure Functions + Azure Batch实现MP3音频转码方案
客户需求 客户的环境是一个网络音乐播放系统,根据网络情况提供给手机用户收听各种码率的MP3歌曲,在客户没购买歌曲的情况下提供一个三十秒内的试听版本.这样一个系统非常明确地一个需求就是会定期需要将一批从 ...
- run commands in linux shell using batch file
adb shell as root after device rooted once device rooted, we must perform "su" before we g ...
- Spring Batch(0)——控制Step执行流程
Conditional Flow in Spring Batch I just announced the new Learn Spring course, focused on the fundam ...
- 【Network】Calico, Flannel, Weave and Docker Overlay Network 各种网络模型之间的区别
From the previous posts, I have analysed 4 different Docker multi-host network solutions - Calico, F ...
- SalesForce 入门
标签: Salesforce.com 一开始是一个云端的销售自动化(Sales Force Automation, SFA)以及客户关系管理工具(Customer Relationship Manag ...
- ContentProvider官方教程(7)3种访问形式:批处理、异步访问、intent间接访问(临时URI权限)
Alternative Forms of Provider Access Three alternative forms of provider access are important in app ...
- 通过SCVMM分配SMB 3.0 文件共享
1.创建SMB群集共享,赋予Hyper-V主机. Hyper-V群集名称.Hyper-V管理员.Hyper-V服务账户完全控制权限 2.VMM提供程序导入 文件服务器(运行方式账户要对文件服务器群集的 ...
- [转]Reducing script compile time or a better workflow to reduce excessive recompiling
http://forum.unity3d.com/threads/148078-Reducing-script-compile-time-or-a-better-workflow-to-reduce- ...
随机推荐
- innobackupex --rsync 报错 Error: can't create file (null)/xtrabackup_rsyncfiles_pass1
在使用最新版的innobackupex(2.3.2): innobackupex /backup --rsync --user=xx --password=xxx 备份时报错: Error: can' ...
- Storm系列(二):使用Csharp创建你的第一个Storm拓扑(wordcount)
WordCount在大数据领域就像学习一门语言时的hello world,得益于Storm的开源以及Storm.Net.Adapter,现在我们也可以像Java或Python一样,使用Csharp创建 ...
- apache指定的网络名不再可用
如果Apache的error.log还是出现大量的:Sat Dec 24 17:21:28 2006] [warn] (OS 64)指定的网络名不再可 用. : winnt_accept: Async ...
- x01.Lab.StreetApp: MVVM
Store App 特别适用于 MVVM 模式.由于要用到 SQLite,Bing Maps,所以第一步从网上搜索并安装这两个扩展.很难想象在智能手机上运行 SQL Server 这种巨无霸型数据库, ...
- getaddrinfo function
The getaddrinfo function provides protocol-independent translation from an ANSI host name to an addr ...
- linux线程同步(5)-屏障
一.概述 barrier(屏障)与互斥量,读写锁,自旋锁不同,它不是用来保护临界区的.相反,它跟条 ...
- HowTo: Linux Server Change OR Setup The Timezone
Method 1 #tzselect # select timezone e.g. Asia/Shanghai#echo 'Asia/Shanghai' > /etc/timezone # se ...
- WPF使用后台C#代码创建Grid
笔者刚刚接触WPF,菜鸟一枚,在做一个练手程序时遇到这样一个需求,创建一个新的Grid并将其添加至一个ListView中,要求Grid及其子元素应按一定顺序给Name属性赋值,直接使用XAML创建的话 ...
- 单机搭建Android开发环境(一)
老话,工欲善其事必先利其器.为了学习安卓系统开发,我下了血本,更换了电脑.俗语,磨刀不误砍柴工,好钢用在刀刃上,为了发挥新本的最大潜能,我花费了很长时间去做配置和优化,都感觉有点偏执了.不过,从到目前 ...
- js的event.srcElement与event.target(触发事件对象)
IE下,event对象有srcElement属性,但是没有target属性; Firefox下,event对象有target属性,但是没有srcElement属性.但他们的作用是相当的,即: fire ...