Script to Create VM with New Storage

$administratorPassword=’Password’
$administratorName=”user”
$machineName=”machinename”.ToLower()+”vm”
$cloudServiceName = $machineName.ToLower()
$storageAccountName = $machineName.ToLower()+”storage”
$vnet=”vnet”
$affinityGroup=Get-AzureAffinityGroup -Name “affinitygroup”
$subscriptionName=”JZado Azure”
$cloudServiceName=$machineName.ToLower()+”svc”

Select-AzureSubscription -SubscriptionName “Some Azure Subscription”

New-AzureStorageAccount -StorageAccountName $storageAccountName -Location $affinityGroup.Location
Set-AzureStorageAccount -GeoReplicationEnabled $false -StorageAccountName $storageAccountName
Set-AzureSubscription -SubscriptionName $subscriptionName -CurrentStorageAccount $storageAccountName -Certificate

$images = Get-AzureVMImage | Where-Object { $_.OS -eq ‘Windows’ -and $_.ImageFamily -eq ‘Windows Server 2012 R2 Datacenter’ -and $_.PublisherName -eq ‘Microsoft Windows Server Group’ } | Sort-Object PublishedDate -Descending | Select-Object -First 1
New-AzureVMConfig -Name $machineName -InstanceSize “Small” -Image $images.ImageName | Add-AzureProvisioningConfig -Windows -AdminUsername $administratorName -Password $administratorPassword | New-AzureVM -ServiceName $cloudServiceName -Location $affinityGroup.Location

Get-AzureVM -ServiceName $cloudServiceName -Name $machineName | Add-AzureProvisioningConfig -EnableWinRMHttp -Windows | Update-AzureVM
Get-AzureVM -ServiceName $cloudServiceName -Name $machineName | Add-AzureDataDisk -CreateNew -DiskSizeInGB 10 -DiskLabel $machineName+”datadisk” -LUN 2 -HostCaching None | Update-AzureVM

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s