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- ...
随机推荐
- MD5 加密 java代码实现
package com.company.fjf; import java.security.MessageDigest; import java.security.NoSuchAlgorithmExc ...
- C#设计模式(21)——责任链模式
一.引言 在现实生活中,有很多请求并不是一个人说了就算的,例如面试时的工资,低于1万的薪水可能技术经理就可以决定了,但是1万~1万5的薪水可能技术经理就没这个权利批准,可能就需要请求技术总监的批准,所 ...
- html页面高亮关键词
function hightLightTheKeyWord(searchParam,$dom){ if(searchParam&&!/^\s*$/.test(searchParam)) ...
- Visual Studio 中的快捷键
VS中常用快捷键 Ctrl+K+D:快速对齐代码 Ctrl+E+D:快速对齐代码 Ctrl+Z:撤销 Ctrl+S:保存 Ctrl+Shift+S:保存所有 Ctrl+J:快速弹出智能提示 Shift ...
- webstorm 10 配置
小弟以前都是用sublime,sublime是一款轻量级的文本编辑器.但是现在要隆重介绍的前端开发工具webstorm,为什么说它是前端开发工具,而不是前端开发编辑器呢?它具备的功能,不只只是编辑器这 ...
- 为什么是 Cloud Service?
怀旧一把,还记得这个界面吗? 没错,这是第一版Windows Azure Management Portal,用Silverlight开发的,很炫! 奇怪,为什么没有Virtual Machine? ...
- 在一周内学会使用 AUTO CAD
学习目的: 1.使用AUTO CAD绘制电路板外框.元器件封装: 2.借助软件使用,对产品结构有更深入的体会. 学习过程: 1.由于本人急需在短时间内具备简单的二维绘图能力,故没有借鉴.对比网络上其他 ...
- 「Mobile Testing Summit China 2016」 中国移动互联网测试大会-议题征集
时至北京盛夏,一场由 TesterHome 主办的关于移动互联网测试技术的盛会正在紧锣密鼓的筹备中.只要你关注软件质量,热爱测试,期待学习,都欢迎你加入这次移动测试技术大会中和我们一起分享经验.探讨话 ...
- HDU5492 Find a path[DP 方差]
Find a path Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- POJ1386Play on Words[有向图欧拉路]
Play on Words Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 11846 Accepted: 4050 De ...