We have two deployment methods on Azure: Resource Manager (ARM) and deployment with PowerShell, which is what we often call classic models. As of 2016/4/6, the century-connected version of Azure does not yet have arm and requires PowerShell for bulk virtual machine deployments.
If you need to build VMs in batches, a single set of portals through the portal, no doubt, is a silly thing. It's time to use PowerShell.
The first step is to have a Microsoft PowerShell first. By logging into your Azure subscription, the steps are not written out in detail here.
Type: get-azurepublishsettingsfile, download the configuration file.
Then type: import-azurepublishsettingsfile "file full path"
The second step is to start creating a Windows virtual machine, specifying the current storage account.
Type:
Set-azuresubscription-subscriptionname ' <SubscriptionName> '-currentstorageaccount ' <StorageAccount> '
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/7E/9A/wKiom1cFBSaC30M0AAAgRoG8IaI955.png "title=" 1.png " alt= "Wkiom1cfbsac30m0aaagrog8iai955.png"/> The third step, find the image of the Windows VM I want to build. Here we assume that the built machine is Windows Server 2012,
First type look for the official image:
$imageList = Get-azurevmimage ' | where {$_. Imagename-like "*windows-server-2012-datacenter*"} $image = $imageList [0]
When you find it, set the image, type:
$imageList = Get-azurevmimage ' | where {$_. Imagename-eq "A699494373c04fc0bc8f2bb1389d6106__windows-server-2012-datacenter-201407.01-en.us-127gb.vhd"}$ Image= $imageList [0]
Fourth step, create the virtual machine, type:
New-azurevmconfig-name ' SHADOW001 '-instancesize ' Small '-imagename $image. Imagename-availabilitysetname ' Avbset ' | Add-azureprovisioningconfig-windows-adminusername ' Shadow '-password ' [email protected]! ' | New-azurevm-servicename ' Shadow '-location ' East Asia '
Di step fifth, batch creation. Batch creation, you need to write a loop-created statement.
Here is an example that has been written. You need to make some changes yourself.
$ScriptBlock = {
Param ([string] $ServiceName, [string] $prefix, [int] $VMnumber)
$SubscriptionName = "Windows Azure Enterprise"
$image =get-azurevmimage|where{$_. Label-eq "Windows Server R2 Datacenter, August (ZH-CN)"}
$imageName = $image [0]. ImageName
$adminName = "* * *"
$ADMINPWD = "* * *"
$vnetName = "* * *"
Set-azuresubscription-subscriptionname $SubscriptionName-currentstorageaccount $ServiceName
[Email protected] ()
for ($i =1; $i-le $VMnumber; $i + +)
{
$instanceSize = "Small"
$newName = ""
if ($i-lt 10)
{
$newName = $prefix + "{0:00}"-F $i
}
Else
{
$newName = $prefix + "{0:0}"-F $i
}
$VM =new-azurevmconfig-imagename $imageName-name $newName-instancesize $instanceSize-availabilitysetname "Cttest"
SET-AZURESUBNET-VM $vm-subnetnames "Subnet-2"
$VM =add-azureprovisioningconfig-vm $vm-windows-adminusername $adminName-password $adminPwd
$vmArray + = $VM
}
New-azurevm-servicename $ServiceName-vms $vmArray-vnetname $vnetName-waitforboot
}
[String] $Array = read-host "Please enter the Cloudservice to create the VM, enter only SERVICE1...SERVICE20, please use ', ' split input '
$ServicArray = @ ()
$ServicArray + = $Array. Split (', ')
[String] $prefix = read-host "Please enter the hostname prefix, beginning with English, can be English + number"
[int] $VMnumber = [int] (read-host "Please enter the number of hosts you need to create and allow only numbers")
foreach ($ServiceName in $ServicArray)
{
Start-job-scriptblock $ScriptBlock-argumentlist $ServiceName, $prefix, $VMnumber
}
$start = Get-date
# 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"
$end =get-date
$timespan = $end-$start
$seconds = $timespan. TotalSeconds
Write-host "Total time $seconds seconds."
This article is from the "Shadow Azure Small Stack" blog, reproduced please contact the author!
Batch deployment of Windows virtual machines on a century-connected version of Microsoft Azure-Deploy with PowerShell