Monday, October 21, 2013

Creating instances for a SharePoint 2013 Windows Azure farm

Unfortunately, Microsoft has decided that you can not install SharePoint 2013 on a domain controller.  This has the unfortunate side effect of mandating that you have at least 2 virtual machines running in order to create a SharePoint 2013 development environment.  ​This post will cover the steps needs for creating a 2 server instances for the SharePoint 2013 development.  One instance will be a simple domain controller.  The other instance will the more traditional server which will contain the production you wish to use for doing your SharePoint development.  This post will NOT cover installing SharePoint or SQL Server or setting up a domain controller.  This post will discuss how to setup the 2 instances in Windows Azure.
This post assumes you already have Windows Azure PowerShell installed locally with the subscription settings and a storage account setup.  If you do not have that already done, then you can view my Getting started with Microsoft Windows Azure PowerShell post for instructions on how to accomplish that.  
  

Script file and Network Config XML for your Domain Controller

Here are the contents of my CreateDC.ps1 script, which I used to create a new Windows Azure instance that will become my domain controller. 
 
$moduleLocation = "C:\Program Files (x86)\Microsoft SDKs\Windows Azure\PowerShell\Azure\Azure.psd1"
$publishSettingsLocation = "<C:\Users\<UserProfile>\Downloads\<SubscriptionName>-credentials.publishsettings>"
$subscriptionName = "Visual Studio Premium with MSDN"
$storageAccountName = "<StorageAccountName>"
$affinityGroup = "<AffinityGroupName>"
$myWindowsAdminPassword = '<local admin account password>'
 
#This will need to unique within this Azure service
$rdpPort = '<the port to use form RDP acccess to this box>'

$myAzureVNetXML = "C:\Azure\scripts\NetworkConfig.xml"
 
#If you rerun the script, you need to supply a unique value for $dcServiceName
$vmname = 'DC1'
 
#This name will need to be unique for Windows Azure, so you may want to make
#this name fairly unique
$dcServiceName = '<service name>'     

$vnet = 'Sp2013VN'

#Import-Module $moduleLocation
#Import-AzurePublishSettingsFile $publishSettingsLocation
Set-AzureSubscription -SubscriptionName $subscriptionName -CurrentStorageAccount $storageAccountName
Select-AzureSubscription -SubscriptionName $subscriptionName

#Create the virtual network based on the settings in the XML file at this path
# note the $affinityGroup, $vmname and $vnet values must those in the NetworkConfile.xml file.
Set-AzureVnetConfig -ConfigurationPath $myAzureVNetXML

# OS Image to Use.  This valus comes from the list of disk images that are
#available.
$image = "a699494373c04fc0bc8f2bb1389d6106__Win2K8R2SP1-Datacenter-201305.01-en.us-127GB.vhd"
 
#VM Configuration
$MyDC = New-AzureVMConfig -name $vmname -InstanceSize 'Small' -ImageName $image |
    Add-AzureProvisioningConfig -Windows -AdminUsername $myWindowsAdminName -Password $myWindowsAdminPassword|
    Set-AzureSubnet -SubnetNames 'Subnet-1' |
    Remove-AzureEndpoint –Name "RDP" |
    Add-AzureEndpoint -LocalPort 3389 -Name 'RDP' -Protocol tcp -PublicPort $rdpPort

New-AzureVM -ServiceName $dcServiceName -AffinityGroup $affinityGroup -VMs $MyDC -VNetName $vnet 
 
 And, here is the contents of the NetworkConfig.xml file mentioned in the above post.
<NetworkConfiguration xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/ServiceHosting/2011/07/NetworkConfiguration">
  <VirtualNetworkConfiguration>
    <Dns>
      <DnsServers>
        <DnsServer name="Sp2013DC" IPAddress="10.0.0.4" />
      </DnsServers>
    </Dns>
    <VirtualNetworkSites>
      <VirtualNetworkSite name="Sp2013VN" AffinityGroup="<AffinityGroupName>">
        <AddressSpace>
          <AddressPrefix>10.0.0.0/8</AddressPrefix>
        </AddressSpace>
        <Subnets>
          <Subnet name="Subnet-1">
            <AddressPrefix>10.0.0.0/11</AddressPrefix>
          </Subnet>
        </Subnets>
        <DnsServersRef>
          <DnsServerRef name="Sp2013DC" />
        </DnsServersRef>
      </VirtualNetworkSite>
    </VirtualNetworkSites>
  </VirtualNetworkConfiguration>
</NetworkConfiguration>
 

Execute the CreateDC PowerShell script

To execute the script file,  ...
 
  1. Open the Windows Azure PowerShell console as Administrator. 
  2. Change directory, CD, to the folder containing the script.  Example CD c:\MyScripts
  3. Enter in the script filename .\CreateDC.ps1
After a several moments, you will have a new Windows Azure service called <service name> that contains 1 virtual machine that will become the domain controller.  You will be able to remote desktop into the domain controller by using <service name>.cloudapp.net:<the port to use form RDP acccess to this box>
 
You will need to remote into that server and promote it to be a domain controller before adding additional virtual machines to this service.
  

Create SharePoint server instance

Here are the contents of my CreateSP.ps1 script, which I used to create a new Windows Azure instance that will become my SharePoint development server.  This virtual machine will be added to the virtual network that I created in the previous steps. 
 
$moduleLocation = "C:\Program Files (x86)\Microsoft SDKs\Windows Azure\PowerShell\Azure\Azure.psd1"
$publishSettingsLocation = "<C:\Users\<UserProfile>\Downloads\<SubscriptionName>-credentials.publishsettings>"
$subscriptionName = "Visual Studio Premium with MSDN"
$storageAccountName = "<StorageAccountName>"
$affinityGroup = "<AffinityGroupName>"
$myWindowsAdminName = '<local admin account name>'
$myWindowsAdminPassword = '<local admin account password>'
$vmname = 'SP2013'
 
#This will need to unique within this Azure service
$rdpPort = '<the port to use form RDP acccess to this box>'
#use the same service name and virtual network name that you used to create your domain controller
$serviceName = '<service name>'
$vnet = '<virtual network>'


Import-Module $moduleLocation
Import-AzurePublishSettingsFile $publishSettingsLocation
Set-AzureSubscription -SubscriptionName $subscriptionName -CurrentStorageAccount $storageAccountName
Select-AzureSubscription -SubscriptionName $subscriptionName
 
 
# OS Image to Use
$image = "a699494373c04fc0bc8f2bb1389d6106__Windows-Server-2012-Datacenter-201306.01-en.us-127GB.vhd"

#VM Configuration
$MyDC = New-AzureVMConfig -name $vmname -InstanceSize 'Medium' -ImageName $image |
         Add-AzureProvisioningConfig -Windows -AdminUsername $myWindowsAdminName -Password $myWindowsAdminPassword|
         Set-AzureSubnet -SubnetNames 'Subnet-1' |
         Remove-AzureEndpoint –Name "RDP" |
         Add-AzureEndpoint -LocalPort 3389 -Name 'RDP' -Protocol tcp -PublicPort $rdpPort

New-AzureVM -ServiceName $serviceName -VMs $MyDC -VNetName $vnet
 

Execute the CreateSP PowerShell script

To execute the script file,  ...
 
  1. Open the Windows Azure PowerShell console as Administrator. 
  2. Change directory, CD, to the folder containing the script.  Example CD c:\MyScripts
  3. Enter in the script filename .\CreateSP.ps1
After a several moments, you will have a new virtual machine created within the Windows Azure service called <service name>.  This server become your SharePoint server.  You will be able to remote desktop into the virtual machine by using <service name>.cloudapp.net:<the port to use form RDP acccess to this box>.
 
 

Uploading a HyperV VHD into Windows Azure and creating a Virtual Instance.

I have several legacy VHDs that are taking up space on my laptop.  I decided to move one of them up to Azure to test how this would work and the potential benefits and drawbacks.  I selected a VHD that is a Windows Server 2003 running SharePoint 2007 (WSS 3.0) and SQL Server 2005.  This is a self contained configured environment.  I put together the following PowerShell script to load the VHD into Windows Azure.  In order to execute this script you must have Windows Azure cmdlets installed locally, your MSDN subscription settings saved locally, and have a Windows Azure storage account setup.

This post assumes you already have Windows Azure PowerShell installed locally with the subscription settings and a storage account setup.  If you do not have that already done, then you can view my Getting started with Microsoft Windows Azure PowerShell post for instructions on how to accomplish that.

Load VHD into Azure Storage Account

Here are the contents of my UploadVHDFile.ps1 script, which I used to upload a HyperV VHD into Windows Azure.

$moduleLocation = "C:\Program Files (x86)\Microsoft SDKs\Windows Azure\PowerShell\Azure\Azure.psd1"
$publishSettingsLocation = "<C:\Users\<UserProfile>\Downloads\<SubscriptionName>-credentials.publishsettings>"
$subscriptionName = "<Visual Studio Premium with MSDN>"
$storageAccountName = "<StorageAccountName>"
$diskName = "<disk name>"
 
# Source VHD
$vhdsource = '<the complete path of the VHD file example: c:\vhds\myimage.vhd>'
 
# Upload Location
$vhddestination= 'http://' + $storageAccountName + '.blob.core.windows.net/vhds/' + $diskName + '.vhd'

Import-Module $moduleLocation
Import-AzurePublishSettingsFile $publishSettingsLocation
    
Add-AzureVhd -LocalFilePath $vhdsource -Destination $vhddestination
    
Add-AzureDisk -OS Windows -MediaLocation $destosvhd -DiskName $diskName


To execute the script file,  ...

  1. I open the Windows Azure PowerShell console as Administrator. 
  2. I change directory, CD, to the folder containing the script.  Example CD c:\MyScripts
  3. I enter in the script filename .\UploadVHDFile.ps1



After serveral minutes / hours, the new DISK will be loaded into your Azure storage account.



 

Create Virtual Machine from Disk


Here are the contents of my CreateVirtualMachine.ps1 script file which I used to create a Virtual Machine from the VHD that I loaded into Windows Azure.

 
$moduleLocation = "C:\Program Files (x86)\Microsoft SDKs\Windows Azure\PowerShell\Azure\Azure.psd1"
$publishSettingsLocation = "<C:\Users\<UserProfile>\Downloads\<SubscriptionName>-credentials.publishsettings>"
$subscriptionName = "<Visual Studio Premium with MSDN>"
$storageAccountName = "<StorageAccountName>"
$diskName = "<disk name>"
$location = 'East US'
 
# Has to be a unique name. Verify with Test-AzureService
$serviceName = "<UNIQUE SERVICE NAME>"

# Server Name
$vmname1 = "<MY VM NAME>"

    
$migratedVM = New-AzureVMConfig -Name $vmname1 -DiskName $diskName -InstanceSize 'Medium' |
     Add-AzureEndpoint -Name 'Remote Desktop' -LocalPort 3389 -Protocol tcp

New-AzureVM -ServiceName $serviceName -Location $location -VMs $migratedVM

 
To execute the script file,  ...



  1. I open the Windows Azure PowerShell console as Administrator. 
  2. I change directory, CD, to the folder containing the script.  Example CD c:\MyScripts
  3. I enter in the script filename .\CreateVirtualMachine.ps1

 
 


After a couple minutes, the new virtual machine will be available for you to use in Windows Azure.

 

 

Benefits and Drawbacks

The huge benefit is that you are able to make a virtual machine more accessible for your use.  You can add more resources be changing the instance size.  You can free up space on your local harddrive.  One additional plus, is that you are able to load images into Windows Azure that are no longer natively supported through their website, such as Windows Server 2003.  The downside is that you now incur a cost.  There is a fee just for storing an image out in Windows Azure.  Plus, you have to pay a cost for the time the Virtual Machine is allocated.   And to be clear, an instance that is Shut Down through windows is still allocated. You must use the Windows Azure website or PowerShell console to stopped the instance so that you don't get charged.

Getting started with Microsoft Windows Azure PowerShell

The http://manage.windowsazure.com/ site is the web based interface that allows a user to manage an Azure environment.  There is also a PowerShell interface that you can use to manage your Azure environment and that is what this article will discuss.  This page, Windows Azure PowerShell, is a great starting resource.  There are a few steps that we need to go through in order to get everything ready for you to start working with Azure Virtual Machines. 


The How to install and configure Windows Azure PowerShell page provides the link that you will need to download Windows Azure PowerShell and connect to your subscription.  I have pulled those 2 sections into this post.

Install Windows Azure PowerShell on your computer

You can download and install the Windows Azure PowerShell module by running the Microsoft Web Platform Installer. When prompted, click Run. The Microsoft Web Platform Installer loads, with the Windows Azure PowerShell module available for installation. The Web Platform Installer installs all dependencies for the Windows Azure PowerShell cmdlets. Follow the prompts to complete the installation. 

On a Windows 8, you should see a Windows Azure PowerShell icon on your start screen.  If you are using the start button, you should have a Windows Azure group and within that group you should see Windows Azure PowerShell.  You should run as administrator when you start the Windows Azure PowerShell console through either one of those methods.

Connect to your subscription

Use of Windows Azure requires a subscription. If you don't have a subscription, see Get Started with Windows Azure.

The cmdlets require your subscription information so that it can be used to manage your services. This information is provided by downloading and then importing it for use by the cmdlets. The Windows Azure PowerShell module includes two cmdlets that help you perform these tasks:

  • The Get-AzurePublishSettingsFile cmdlet opens a web page on the [Windows Azure Management Portal]( from which you can download the subscription information. The information is contained in a .publishsettings file.
  • The Import-AzurePublishSettingsFile imports the .publishsettings file for use by the module. This file includes a management certificate that has security credentials.

Important
We recommend that you delete the publishing profile that you downloaded using Get-AzurePublishSettingsFileafter you import those settings. Because the management certificate includes security credentials, it should not be accessed by unauthorized users. If you need information about your subscriptions, you can get it from the Windows Azure Management Portal or the Microsoft Online Services Customer Portal.

  1. Sign in to the Windows Azure Management Portal using the credentials for your Windows Azure account.
  2. Open the Windows Azure PowerShell console, as instructed in How to: Install Windows Azure PowerShell.
  3. Type the following command:
    Get-AzurePublishSettingsFile
  4. When prompted, download and save the publishing profile and note the path and name of the .publishsettings file. This information is required when you run the Import-AzurePublishSettingsFile cmdlet to import the settings. The default location and file name format is:
    C:\Users\<UserProfile>\Desktop\[MySubscription-…]-downloadDate-credentials.publishsettings
  5. Type a command similar to the following, substituting your Windows account name and the path and file name for the placholders:
    Import-AzurePublishSettingsFile C:\Users\<UserProfile>\Downloads\<SubscriptionName>-credentials.publishsettings
  6. To view the subscription information, type:
    Get-AzureSubscription

Next: Create an Azure Affinity Group

According to Create an Affinity Group in the Management Portal, an Azure Affinity Group allows you to group your Windows Azure services to optimize performance. All services within an affinity group will be located in the same data center. An affinity group is required in order to create a virtual network.

  1. Open the Windows Azure PowerShell console as Administrator.
  2. Import your subscription information using this command:
    Import-AzurePublishSettingsFile "C:\Users\<UserProfile>\Downloads\<SubscriptionName>-credentials.publishsettings"

  3. Type the following command:
    New-AzureAffinityGroup -Name <affinitygroup> -Location "East US" -Label "East US" -Description "Affinity group for production applications in East US."

Finally: Create a Storage Account

According to How To Create a Storage Account, an Azure Storage Account is how you store files and data in the Blob, Table, and Queue services in Windows Azure.  You assign your storage account to a geographic region where you want to store the data.  A storage account can contain up to 100 TB of blob, table, and queue data. You can create up to five storage accounts for each Windows Azure subscription.

You can setup a storage account using the New-AzureStorageAccount cmdlet.  The following steps provide an example of how to do this.  The steps assume you are opening a new Windows Azure PowerShell console.  You can skip to step 3 if you already have a console window open.
Open the Windows Azure PowerShell console as Administrator.
  1. Import your subscription information using this command:
    Import-AzurePublishSettingsFile "C:\Users\<UserProfile>\Downloads\<SubscriptionName>-credentials.publishsettings"

  2. Type the following command:
    New-AzureStorageAccount -StorageAccountName <StorageAccountName> -AffinityGroup <affinitygroup> -Location "East US"
  3. Type the following command:
    New-AzureStorageAccount -StorageAccountName <StorageAccountName> -AffinityGroup <affinitygroup> -Location "East US"