0

Introduction to PowerShell for Azure – Creating a VM

<pre>&lt;#
.SNOPSYS
Excute Basic Azure command and create a VM

.DESCRIPTION
This script is meant for education/demonstration purpose only
and not meant for production use
- Initial section of the script covers basics commands to get connected with Azure
- The rest of the script covers creating a VM with SQL Server running.

.NOTES
Author: Susheel Dakoju
Date Authored: 04/13/2015
#&gt;
#-----------------------------------------------------------------------------
# 1. Connect to Azure: Option 1: Add-AzureAccount
#-----------------------------------------------------------------------------
#Connect
Add-AzureAccount
#Check subscription details
Get-AzureSubscription
#-----------------------------------------------------------------------------
# 1. Connect to Azure: Option 2: Get-AzurePublishSettingsFiles
#-----------------------------------------------------------------------------
#Download PublishSettingsFile
Get-AzurePublishSettingsFile
#Import Setting Files
Import-AzurePublishSettingsFile "C:PowershellAzureVisual Studio Ultimate with MSDN-4-14-2015-credentials.publishsettings"

#-----------------------------------------------------------------------------
# 2. Export all the exiting images in the VM Gallery and
# copy the name image you want to create
# Note: There are more elegant way of doing this.Here the most basic form is demonstration. See below
&lt;#
$vmimages | where {$_.Label -like 'sql server 2014*'} | select Label, RecommendedVMSize, PublishedDate | Format-Table -AutoSize
$imgtouse = $vmimages | where {$_.Label -eq 'SQL Server 2014 RTM Enterprise on Windows Server 2012 R2' `
-and $_.PublishedDate -eq '6/9/2014 3:00:00 AM'} | select ImageName
#&gt;
#-----------------------------------------------------------------------------
Get-AzureVMImage &gt; C:PowershellAzureimages.txt

#-----------------------------------------------------------------------------
# 3. Create new Azure VM
#-----------------------------------------------------------------------------
New-AzureVMConfig -Name 'sdcapsandbox1' -InstanceSize Basic_A3 -ImageName 'fb83b3509582419d99629ce476bcb5c8__SQL-Server-2014-RTM-12.0.2361.0-Enterprise-ENU-Win2012R2-cy14su05' |`
Add-AzureProvisioningConfig -Windows -AdminUsername 'sdcapsandboxuser1' -Password 'Administrator@1234'|`
New-AzureVM -Location 'East US' -ServiceName 'sdcapsandbox1'
#-----------------------------------------------------------------------------
# 3.Check if the New VM is generated
#-----------------------------------------------------------------------------
#Get-AzureVM

#------------------------------------------------------------------------------------
# Optional: If New-AzureVM errors out on storage account. Keep the following handy
# - Use one of the storage accounts or create a new one run Set-AzureSubscription
#------------------------------------------------------------------------------------
#Get-AzureStorageAccount
#Set-AzureSubscription -SubscriptionId 16c41f83-c83e-476a-8fdc-51b8ae69849f -CurrentStorageAccount mystorageaccount
</pre>

Leave a Reply