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

http://sqlblog.com/blogs/marco_russo/archive/2013/10/29/powershell-script-to-deploy-multiple-vm-on-azure-in-parallel-azure-powershell.aspx

How to create a batch of VMs with PowerShell的更多相关文章

  1. 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 ...

  2. Azure Functions + Azure Batch实现MP3音频转码方案

    客户需求 客户的环境是一个网络音乐播放系统,根据网络情况提供给手机用户收听各种码率的MP3歌曲,在客户没购买歌曲的情况下提供一个三十秒内的试听版本.这样一个系统非常明确地一个需求就是会定期需要将一批从 ...

  3. 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 ...

  4. Spring Batch(0)——控制Step执行流程

    Conditional Flow in Spring Batch I just announced the new Learn Spring course, focused on the fundam ...

  5. 【Network】Calico, Flannel, Weave and Docker Overlay Network 各种网络模型之间的区别

    From the previous posts, I have analysed 4 different Docker multi-host network solutions - Calico, F ...

  6. SalesForce 入门

    标签: Salesforce.com 一开始是一个云端的销售自动化(Sales Force Automation, SFA)以及客户关系管理工具(Customer Relationship Manag ...

  7. ContentProvider官方教程(7)3种访问形式:批处理、异步访问、intent间接访问(临时URI权限)

    Alternative Forms of Provider Access Three alternative forms of provider access are important in app ...

  8. 通过SCVMM分配SMB 3.0 文件共享

    1.创建SMB群集共享,赋予Hyper-V主机. Hyper-V群集名称.Hyper-V管理员.Hyper-V服务账户完全控制权限 2.VMM提供程序导入 文件服务器(运行方式账户要对文件服务器群集的 ...

  9. [转]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- ...

随机推荐

  1. linux添加开机自启动脚本示例详解

    linux下(以RedHat为范本)添加开机自启动脚本有两种方法,先来简单的; 一.在/etc/rc.local中添加如果不想将脚本粘来粘去,或创建链接什么的,则:step1. 先修改好脚本,使其所有 ...

  2. Tomcat免安装配置2

    Tomcat 是一款优秀的JSP/Servlet容器,最初由SUN开发,后来被贡献给了Apache社区.Tomcat现在的版本已到6.Tomcat6实现了Servlet2.5和JSP2.1规范.针对w ...

  3. Windows Azure 虚拟机的IP地址操作

    Windows Azure上的一个虚拟机对应两个IP地址,VIP和DIP. VIP,公网IPv4地址,动态分配.虚拟机停止(deallocate,在管理控制台上关机或者使用PowerShell关机)后 ...

  4. Java开发之JSP指令

    一.page指令 page指令是最常用的指令,用来说明JSP页面的属性等.JSP指令的多个属性可以写在一个page指令里,也可以写在多个指令里.但需要注意的是,无论在哪个page指令里的属性,任何pa ...

  5. 【转】selenium学习路线

    selenium学习路线 配置你的测试环境,真对你所学习语言,来配置你相应的selenium 测试环境.selenium 好比定义的语义---“问好”,假如你使用的是中文,为了表术问好,你的写法是“你 ...

  6. 文件上传&文件下载

    一.单个文件上传 文件上传需要两个jar包: 首先制作一个简单的页面,用于实现文件上传 <h1>单个文件上传</h1> <s:form action="uplo ...

  7. 微软极品工具箱-Sysinternals Suite

    工具包由来 Sysinternals Suite是微软发布的一套非常强大的免费工具程序集,一共包括74个windows工具.Sysinternals是Winternals公司提供的免费工具,Winte ...

  8. Teredo 是一项 IPv6/IPv4 转换技术

     Teredo 是一项 IPv6/IPv4 转换技术,能够实现在处于单个或者多个 IPv4 NAT 后的主机之间的 IPv6 自动隧道.来自 Teredo 主机的 IPv6 数据流能够通过 NAT,因 ...

  9. LESS速查

    注释 缓存式注释/*注释内容*/  非缓存式注释//注释内容 变量 @nice-blue: #5B83AD; @light-blue: @nice-blue + #111; #header { col ...

  10. Apache和Tomcat区别

    Apache 和 Tomcat 都是web网络服务器,两者既有联系又有区别,在进行HTML.PHP.JSP.Perl等开发过程中,需要准确掌握其各自特点,选择最佳的服务器配置.Apache是web服务 ...