With the new Azure Virtual Machines it is now possible to run SharePoint 2010 and 2013 workloads. In my TechEd talks you can learn about the various options to run SharePoint on Azure.

http://channel9.msdn.com/Events/TechEd/NorthAmerica/2012/AZR327

and

http://channel9.msdn.com/Events/TechEd/Europe/2012/OSP334

I won’t rehash those talks again here. What I do want to share is some of the PowerShell code I used to build the farms. First a caveat that these are just rough scripts that I used to build the demo and have lots of opportunities for improvements. The script are good at demonstrating the various steps that are involved with building the Farm. Here is a diagram of the farm that we will build.

image

To get started read Automating Windows Azure Virtual Machines with PowerShell. Also if you are new to Azure Virtual Machines here is a crash course on the features that we will cover in the PowerShell scripts: Learn about Windows Azure Virtual Machines. With that out of the way let’s get started.

Create VNet

The first step is to create the virtual network. In the past the Cloud Service (previously called hosted services) was the container for multiple VMs to talk to each other. Now the Virtual Network (VNet) allows multiple Cloud Services to talk to each other. So in the case of our Farm we want the Active Directory/Domain Controller (AD/DC) to be in one Cloud Service and talk to the rest of our farm in another Cloud Service. By using 2 Cloud Services, you can start the AD/DC first and have the other Cloud Services join the domain, since we do not have static IPs. Here is the script to create the VNet.

CreateVnet.ps1
  1. # To get started
  2. # http://msdn.microsoft.com/en-us/library/windowsazure/jj156055.aspx
  3.  
  4. CLS
  5.  
  6. # List imported subscriptions
  7. # get-AzureSubscription | Select SubscriptionName
  8.  
  9. # your imported subscription name
  10. $subscriptionName = "My Azure Subscription"
  11. $storageAccount = "2010storage"
  12. Select-AzureSubscription $subscriptionName
  13. Set-AzureSubscription $subscriptionName -CurrentStorageAccount $storageAccount
  14.  
  15. # List all locations to determine $AGLocation
  16. #Get-AzureLocation | Select Name
  17.  
  18. # Affinity Group parameters
  19. $AGLocation = "West US"
  20. $AGDesc = "SharePoint 2010 Affinity Group"
  21. $AGName = "SP2010-AG"
  22. $AGLabel = "SP2010-AG"
  23.  
  24. # Create a new affinity Group
  25. New-AzureAffinityGroup -Location $AGLocation -Description $AGDesc `
  26.                                         -Name $AGName -Label $AGLabel
  27.  
  28. # Clear current settings
  29. Remove-AzureVNetConfig -ErrorAction SilentlyContinue
  30.  
  31. # Apply new network
  32. $configPath = (Split-Path -Path $MyInvocation.MyCommand.Definition -Parent) `
  33.                     + "\SharePointFarmVNET.xml"
  34.  
  35. Set-AzureVNetConfig -ConfigurationPath $configPath
  36.  
  37. # Check results
  38. #Get-AzureVNetConfig | Select -ExpandProperty XMLConfiguration
  39.  
  40. #Create Storage account for SP Farm
  41.  
  42. # The storage account name must be unique to Windows Azure and
  43. # must be between 3 and 24 characters in length and
  44. # use lowercase letters and numbers only.
  45.  
  46. #$storageAccountName = "sharepointfarm"
  47. #$label = "SharePoint Storage Account"
  48. #New-AzureStorageAccount -StorageAccountName $storageAccountName `
  49. #                                        -Label $label -AffinityGroup $AGName

 

Create AD/DC

Once the VNet is in place you can create the Active Directory/Domain Controller. All this script does is create a VM in a Cloud Service. Once the VM is started you will need to manually RDP connect to the machine and run DCPROMO. Once DCPROMO is finished run ipconfig to determine the IP of the machine, which will be used in the Farm setup script.

CreateDC.ps1
  1. # To get started
  2. # http://msdn.microsoft.com/en-us/library/windowsazure/jj156055.aspx
  3.  
  4. CLS
  5.  
  6. # List imported subscriptions to determine $subscriptionName
  7. # get-AzureSubscription | Select SubscriptionName
  8.  
  9. # List storage accounts to determine $storageAccount
  10. #Get-AzureStorageAccount | select StorageAccountName
  11.  
  12. # your imported subscription name
  13. $subscriptionName = "My Azure Subscription"
  14. $storageAccount = "2010storage"
  15. Select-AzureSubscription $subscriptionName
  16. Set-AzureSubscription $subscriptionName -CurrentStorageAccount $storageAccount
  17.  
  18. #List all images to determine $imagename
  19. #Get-AzureVMImage | Select ImageName
  20.  
  21. #List Vnet config to determine $vnetname and $subnetname
  22. #Get-AzureVNetConfig | Select -ExpandProperty XMLConfiguration
  23.  
  24.  
  25. ## Domain Controller 1 Paramaters
  26. $vmName = 'SP2010-DC1'
  27. $imageName = 'MSFT__Win2K8R2SP1-120612-1520-121206-01-en-us-30GB.vhd'
  28. $size = "ExtraSmall"
  29. $vmStorageLocation = "http://2010storage.blob.core.windows.net/vhds/SP2010Farm/SP2010-DC1.vhd"
  30. $deploymentName = "SP2010-DC1-Deployment"
  31. $deploymentlabel = "SharePoint 2010 DC1 Deployment"
  32. $subnet = 'SP2010AD-Subnet'
  33. $password = 'pass@word1'
  34.  
  35. ## Create VM Configuration
  36. $dc1 = New-AzureVMConfig -Name $vmName -InstanceSize $size `
  37.     -ImageName $imageName -MediaLocation $vmStorageLocation
  38. Add-AzureProvisioningConfig -Windows -Password $password -VM $dc1
  39. Set-AzureSubnet -SubnetNames $subnet -VM $dc1
  40.  
  41. ## Cloud Service Paramaters
  42. $serviceName = "SP2010DC-Service"
  43. $serviceLabel = "SP2010DC-Service"
  44. $serviceDesc = "Domain Controller for SharePoint 2010"
  45. $vnetname = 'SP2010-VNET'
  46. $ag = 'SP2010-AG'
  47.  
  48. ## Create the VM(s)
  49. New-AzureVM -ServiceName $serviceName -ServiceLabel $serviceLabel -ServiceDescription $serviceDesc `
  50.                         -AffinityGroup $ag -VNetName $vnetname -VMs $dc1

Create Farm

The last step is to create the SharePoint Farm.

CreateSPFarm.ps1
  1. # To get started
  2. # http://msdn.microsoft.com/en-us/library/windowsazure/jj156055.aspx
  3.  
  4. CLS
  5.  
  6. # List imported subscriptions to determine $subscriptionName
  7. # get-AzureSubscription | Select SubscriptionName
  8.  
  9. # List storage accounts to determine $storageAccount
  10. #Get-AzureStorageAccount | select StorageAccountName
  11.  
  12. # your imported subscription name
  13. $subscriptionName = "My Azure Subscription"
  14. $storageAccount = "2010storage"
  15. Select-AzureSubscription $subscriptionName
  16. Set-AzureSubscription $subscriptionName -CurrentStorageAccount $storageAccount
  17.  
  18. # Cloud Service Paramaters
  19. $serviceName = "SP2010-Service"
  20. $serviceLabel = "SP2010-Service"
  21. $serviceDesc = "Cloud Service for SharePoint Farm"
  22.  
  23. #List Vnet config to determine $vnetname and $subnetName
  24. #Get-AzureVNetConfig | Select -ExpandProperty XMLConfiguration
  25.  
  26. # Gallery Images
  27.   $spimage= 'MSFT__Win2K8R2SP1-120612-1520-121206-01-en-us-30GB.vhd'
  28. $sqlimage = 'MSFT__Sql-Server-11EVAL-11.0.2215.0-05152012-en-us-30GB.vhd'
  29. $vnetname = 'SP2010-VNET'
  30. $subnetName = 'SP2010Farm-Subnet'
  31. $ag = 'SP2010-AG'
  32. $primaryDNS = '192.168.1.4'
  33.  
  34. # Availability Sets
  35. $avsetwfe = 'avsetwfe'
  36. $avsetapps = 'avsetapps'
  37. $avsetsql = 'avsetsql'
  38.  
  39. # Domain Settings
  40. $domain = 'contoso'
  41. $joindom = 'contoso.com'
  42. $domuser = 'administrator'
  43. $dompwd = 'pass@word1'
  44. $advmou = 'OU=AzureVMs,DC=contoso,DC=com'
  45.  
  46. # MediaLocation
  47. $mediaLocation = "http://2010storage.blob.core.windows.net/vhds/SP2010Farm/"
  48.  
  49. ## Create SP WFE1
  50. $size = "ExtraSmall"
  51. $vmStorageLocation = $mediaLocation + "SP2010-WFE1.vhd"
  52. $spwfe1 = New-AzureVMConfig -Name 'SP-WFE1' -AvailabilitySetName $avsetwfe `
  53.             -ImageName $spimage -InstanceSize $size -MediaLocation $vmStorageLocation |
  54.         Add-AzureProvisioningConfig -WindowsDomain -Password $dompwd `
  55.             -Domain $domain -DomainUserName $domuser -DomainPassword $dompwd `
  56.             -MachineObjectOU $advmou -JoinDomain $joindom |
  57.         Add-AzureEndpoint -Name 'http' -LBSetName 'lbhttp' -LocalPort 80 -PublicPort 80 `
  58.             -Protocol tcp -ProbeProtocol http -ProbePort 80 -ProbePath '/healthcheck/iisstart.htm' |
  59.         Set-AzureSubnet $subnetName
  60.         
  61. ## Create SP WFE2
  62. $size = "ExtraSmall"
  63. $vmStorageLocation = $mediaLocation + "SP2010-WFE2.vhd"
  64. $spwfe2 = New-AzureVMConfig -Name 'SP-WFE2' -AvailabilitySetName $avsetwfe -ImageName $spimage -InstanceSize $size -MediaLocation $vmStorageLocation |
  65.         Add-AzureProvisioningConfig -WindowsDomain -Password $dompwd -Domain $domain -DomainUserName $domuser -DomainPassword $dompwd -MachineObjectOU $advmou -JoinDomain $joindom |
  66.         Add-AzureEndpoint -Name 'http' -LBSetName 'lbhttp' -LocalPort 80 -PublicPort 80 -Protocol tcp -ProbeProtocol http -ProbePort 80 -ProbePath '/healthcheck/iisstart.htm' |
  67.         Set-AzureSubnet $subnetName
  68.  
  69. ## Create SP WFE3
  70. $size = "ExtraSmall"
  71. $vmStorageLocation = $mediaLocation + "SP2010-WFE3.vhd"
  72. $spwfe3 = New-AzureVMConfig -Name 'SP-WFE3' -AvailabilitySetName $avsetwfe -ImageName $spimage -InstanceSize $size -MediaLocation $vmStorageLocation |
  73.         Add-AzureProvisioningConfig -WindowsDomain -Password $dompwd -Domain $domain -DomainUserName $domuser -DomainPassword $dompwd -MachineObjectOU $advmou -JoinDomain $joindom |
  74.         Add-AzureEndpoint -Name 'http' -LBSetName 'lbhttp' -LocalPort 80 -PublicPort 80 -Protocol tcp -ProbeProtocol http -ProbePort 80 -ProbePath '/healthcheck/iisstart.htm' |
  75.         Set-AzureSubnet $subnetName
  76.  
  77. ## Create SP WFE4
  78. $size = "ExtraSmall"
  79. $vmStorageLocation = $mediaLocation + "SP2010-WFE4.vhd"
  80. $spwfe4 = New-AzureVMConfig -Name 'SP-WFE4' -AvailabilitySetName $avsetwfe -ImageName $spimage -InstanceSize $size -MediaLocation $vmStorageLocation |
  81.         Add-AzureProvisioningConfig -WindowsDomain -Password $dompwd -Domain $domain -DomainUserName $domuser -DomainPassword $dompwd -MachineObjectOU $advmou -JoinDomain $joindom |
  82.         Add-AzureEndpoint -Name 'http' -LBSetName 'lbhttp' -LocalPort 80 -PublicPort 80 -Protocol tcp -ProbeProtocol http -ProbePort 80 -ProbePath '/healthcheck/iisstart.htm' |
  83.         Set-AzureSubnet $subnetName
  84.  
  85. ## Create SP App1
  86. $size = "ExtraSmall"
  87. $vmStorageLocation = $mediaLocation + "SP2010-APP1.vhd"
  88. $spapp1 = New-AzureVMConfig -Name 'SP-APP1' -AvailabilitySetName $avsetapps -ImageName $spimage -InstanceSize $size -MediaLocation $vmStorageLocation |
  89.         Add-AzureProvisioningConfig -WindowsDomain -Password $dompwd -Domain $domain -DomainUserName $domuser -DomainPassword $dompwd -MachineObjectOU $advmou -JoinDomain $joindom |
  90.         Set-AzureSubnet $subnetName
  91.         
  92. ## Create SP App2
  93. $size = "ExtraSmall"
  94. $vmStorageLocation = $mediaLocation + "SP2010-APP2.vhd"
  95. $spapp2 = New-AzureVMConfig -Name 'SP-APP2' -AvailabilitySetName $avsetapps -ImageName $spimage -InstanceSize $size -MediaLocation $vmStorageLocation |
  96.         Add-AzureProvisioningConfig -WindowsDomain -Password $dompwd -Domain $domain -DomainUserName $domuser -DomainPassword $dompwd -MachineObjectOU $advmou -JoinDomain $joindom |
  97.         Set-AzureSubnet $subnetName
  98.  
  99. ## Create SQL Server1
  100. $size = "ExtraSmall"
  101. $vmStorageLocation = $mediaLocation + "SP2010-SQL1.vhd"
  102. $spsql1 = New-AzureVMConfig -Name 'SP-SQL1' -AvailabilitySetName $avsetsql -ImageName $sqlimage -InstanceSize $size -MediaLocation $vmStorageLocation |
  103.         Add-AzureProvisioningConfig -WindowsDomain -Password $dompwd -Domain $domain -DomainUserName $domuser -DomainPassword $dompwd -MachineObjectOU $advmou -JoinDomain $joindom |
  104.         Add-AzureDataDisk -CreateNew -DiskSizeInGB 100 -DiskLabel 'data' -LUN 0 |
  105.         Set-AzureSubnet $subnetName
  106.         
  107. ## Create SQL Server 2
  108. #$spsql2 = New-AzureVMConfig -Name 'SP-SQL2' -AvailabilitySetName $avsetsql -ImageName $sqlimage -InstanceSize Large |
  109. #        Add-AzureProvisioningConfig -WindowsDomain -Password $dompwd -Domain $domain -DomainUserName $domuser -DomainPassword $dompwd -MachineObjectOU $advmou -JoinDomain $joindom |
  110. #        Add-AzureDataDisk -CreateNew -DiskSizeInGB 100 -DiskLabel 'data' -LUN 0 |
  111. #        Add-AzureDataDisk -CreateNew -DiskSizeInGB 100 -DiskLabel 'logs' -LUN 1 |
  112. #        Set-AzureSubnet $sqlsubnet
  113.     
  114. #$spsql3 = New-AzureVMConfig -Name 'SP-SQLWitness' -ImageName $sqlimage -InstanceSize Large |
  115. #        Add-AzureProvisioningConfig -WindowsDomain -Password $dompwd -Domain $domain -DomainUserName $domuser -DomainPassword $dompwd -MachineObjectOU $advmou -JoinDomain $joindom |
  116. #        Set-AzureSubnet $sqlsubnet
  117.         
  118.     
  119. $dns1 = New-AzureDns -Name 'dns1' -IPAddress $primaryDNS
  120.  
  121. New-AzureVM -ServiceName $serviceName -ServiceLabel $serviceLabel `
  122.             -ServiceDescription $serviceDesc `
  123.             -AffinityGroup $ag -VNetName $vnetname -DnsSettings $dns1 `
  124.             -VMs $spwfe1,$spwfe2,$spwfe3,$spwfe4,$spapp1, $spapp2, $spsql1
  125.             
  126.