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系统中,通过rm删除文件将会从文件系统的目录结构上解除链接(unlink),如果文件是被打开的(有一个进程正在使用),那么进程将仍然可以读取该文件磁盘空间也一直被占用 这样就 ...

  2. mongodb的备份

    转载请附原文链接:http://www.cnblogs.com/wingsless/p/5672057.html mongodb现在为止还是没有像XtraBackup这样好用的备份工具,因此一般来说会 ...

  3. ARM体系结构

    工作模式_ufisaus USR(User) :正常程序的执行状态 FIQ(Fast interrupt) :用于高速数据传输和通道处理 IRQ(Interrupt) :通常的中断处理 SVC(Sup ...

  4. Linux IPC POSIX 共享内存

    模型 #include <unistd.h> //for fstat() #include <sys/types.h> //for fstat() #include <s ...

  5. linux下怎么查看ssh的用户登录日志

    linux下登录日志在下面的目录里: cd /var/log 查看ssh用户的登录日志: less secure linux日志管理: 1. 日志简介 日志对于安全来说,非常重要,他记录了系统每天发生 ...

  6. FTP定时批量下载文件(SHELL脚本及使用方法 )

    1. 脚本实例 将以下脚本保存为 getftp.sh #!/bin/bash  datesign=`date -d -95day +%Y%m%d` ftp -nv 12.2.2.28 << ...

  7. php高级研发或架构师必了解---很多问题面试中常问到!

    一.mysql相关知识    1. mysql优化方式            MYSQL 优化常用方法            mysql 性能优化方案      2.如何分库分表            ...

  8. HADOOP HDFS的设计

    Hadoop提供的对其HDFS上的数据的处理方式,有以下几种, 1 批处理,mapreduce 2 实时处理:apache storm, spark streaming , ibm streams 3 ...

  9. 通过三张图了解Redux中的重要概念

    上周利用业余的时间看了看Redux,刚开始有点不适应,一下在有了Action.Reducer.Store和Middleware这么多新的概念. 经过一些了解之后,发现Redux的单向数据里的模式还是比 ...

  10. WPF自定义空心文字

    首先创建一个自定义控件,继承自FrameworkElement,“Generic.xaml”中可以不添加样式. 要自定义空心文字,要用到绘制格式化文本FormattedText类.FormattedT ...