Azure PowerShell Bulk Create azure virtual machines

Source: Internet
Author: User

As we work, you may need to create more than one virtual machine of the same configuration. Can we only create it from a single station on the portal page? The answer is no, we can create virtual machines in bulk using Azure PowerShell scripts. Next I'll cover the bulk creation of azure virtual machines through PowerShell.

The contents of the following split line are the contents of the PowerShell script used to create the virtual machine in bulk

---------------------------------------Split Line-----------------------------------------------

# Specify Subscription Name
$subscriptionName = "HUANGCJ test";
# Specify the storage used to save the virtual machine VHD
$storageAccount = "Hcjtest";
# Create an array to hold the configuration information created by the virtual machine
$vms =new-object System.Collections.ArrayList;
# Get a list of virtual machine images
$images =get-azurevmimage;
# Get the name of the 43rd image (Win Server R2)
$imageName = $images [43]. ImageName;
# Name of the cloud service
$cloudServiceName = "Hcjtest";
# Set the default subscription and the storage account associated with the default subscription
Select-azuresubscription–subscriptionname $subscriptionName –default
Set-azuresubscription-subscriptionname $subscriptionName-currentstorageaccountname $storageAccount
# Executes the loop, generates an array of virtual machine configurations, counts from 0 onwards, and ends at 19, creating hcjse0,hcjser1,hcjser2 .... Hcjser19 these virtual machines
for ($i =0; $i le; $i + +)
{
#Hcjser是创建的虚拟机名称的前缀
$vmName = "Hcjser" + $i;
# Create virtual machine configuration information (virtual machine name, virtual machine size small, virtual machine image name, user name, password, virtual network subnet name, etc. (can be omitted))
# Optional virtual machines instancesize: Extrasmall, Small, Medium, Large, Extralarge, A5, A6, A7, A8, A9, basic_a0, BASIC_A1, BASIC_A2, Basi C_a3, Basic_a4, Standard_d1, Standard_d2, Standard_d3, Standard_d4, Standard_d11, Standard_d12, Standard_D13, Standard_ D14
$VM =new-azurevmconfig–name $vmName –instancesize small–imagename $imageName | Add-azureprovisioningconfig-windows-adminusername huangcj-password 1qaz2wsxe-timezone "China Standard Time" – Disableautomaticupdates | Set-azuresubnet-subnetnames ' Subnet-1 ';
# Add configuration information to the array for the last step command
$vms. Add ($VM);
}
# Create virtual machines in bulk, use the-vms parameter to create a previously created virtual machine configuration array as a parameter, and specify the name of the virtual network and the location parameters and cloud service name
New-azurevm-location "China East" –servicename $cloudServiceName –vms $vms-vnetname ' hcjtestnet '

--------------------------------Split Line------------------------------------------------------

Copy the contents of the above split line into Notepad, modify the relevant parameters for your own actual parameter values, and save the file in. ps1 format.

Run Azure Powershell, and then enter the file path for the PS1 script that you just saved (you can drag the script directly to the Powershell interface, and then enter the "&" + <), and the following is the effect of the execution:

650) this.width=650; "title=" image "style=" border-top:0px; border-right:0px; border-bottom:0px; border-left:0px; Display:inline "border=" 0 "alt=" image "src=" http://s3.51cto.com/wyfs02/M00/8C/36/ Wkiom1hlmhgc1zalaaguoks2fc0047.png "" 637 "height=" 484 "/>

Once execution is complete, we go to the Azure Portal Management page to check the

650) this.width=650; "title=" image "style=" border-top:0px; border-right:0px; border-bottom:0px; border-left:0px; Display:inline "border=" 0 "alt=" image "src=" http://s3.51cto.com/wyfs02/M01/8C/36/wKiom1hlMHLCo-35AAE_ U4hvmpm197.png "" 644 "height=" 342 "/>

You can see that 20 virtual machines have been created.

Azure PowerShell Bulk Create azure virtual machines

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.