PS脚本批量创建机器
使用Azure PowerShell批量创建机器
在熟练使用Azure之后,其实不用登录Azure Portal来手动操作费,只需要使用PowerShell登录进行资源管理和资源创建即可,下面我给大家提供一个批量创建机器的脚本,有兴趣的朋友可以参看。
#################################################################################################
#Before useing this script, Please create below three resources manually on Azure Portal first.
#1.One resource group
#2.One virtual network and create one subnet in this resource group
#3.One diag storage account
#4.This script come from@:www.sugoar.com
#################################################################################################
#Log In Azure:
#Login-AzureRmAccount -EnvironmentName AzureChinaCloud | Out-Null
#Set Location(chinanorth/chinanorth2/chinaeast/chinaeast2):
$location = “chinanorth2”
#Set VMs Size:
$vmSize = “Standard_DS3_V2”
#write-host “n
tDefault set is create Linux VM, if you want to create Windows VM,pleare input “n” to exit and reset osDiskSize, Continue to create please input “y”” -ForegroundColor Yellow
#KaTeX parse error: Expected 'EOF', got '#' at position 51: …r Exit? (y/n)" #̲if(input -eq “n”){Exit}
#If Create Linux VM please use this OS Disk Size
#$osDiskSzie = ‘30’
#If Create Windows VM please use this OS Disk Size
$osDiskSzie = ‘127’
#Get the Resource Group created for those VMs:
$ResourceGroup = Get-AzureRmResourceGroup | Select ResourceGroupName,Location | Out-GridView -PassThru -Title “Select your ResourceGroup”
#Get the diageStorage Account created for those VMs:
write-host “n
tPleare select the diag storage account for those VMs” -ForegroundColor Green
$StorageAccount = (Get-AzureRmStorageAccount | Select StorageAccountName,ResourceGroupName,Location | Out-GridView -PassThru -Title “Select your diag Storage Account”).StorageAccountName
#Get the Virtual Network and Subnet created for those VMs:
$Subnet = Get-AzureRmVirtualNetwork | Get-AzureRmVirtualNetworkSubnetConfig | Select Name,Id,AddressPrefix| Out-GridView -PassThru -Title “Select your Subnet”
#Set VM name prefix:
$vmNames = “”
#User name and Password for VMs:
$user=""
$pwd=ConvertTo-SecureString “” -AsPlainText -Force
$ c r e d = N e w − O b j e c t S y s t e m . M a n a g e m e n t . A u t o m a t i o n . P S C r e d