This project is read-only.

Azure Lab Sample Script

Apr 30, 2015 at 1:42 PM
Is there a sample script for creating a lab in Azure? Or just some lines to get one started.
Apr 30, 2015 at 2:26 PM
Right, some documentation is missing here. I will provide a sample tomorrow that covers the general scenarios.
Apr 30, 2015 at 4:30 PM
Here you go.

The following scripts deployes this on Azure:
  • ContosoDC1, Windows 2008R2, Domain Controller
  • ContosoDC2, Windows 2008R2, Domain Controller
  • ContosoEx1, Windows 2012R2, Exchange 2013 Server, additional 100 GB Disk
  • ContosoEx2, Windows 2012R2, Exchange 2013 Server, additional 100 GB Disk
  • ContosoSrv1, Windows 2012R2, only RSAT
The roles WebServer, SQLServer2012 and 2014, CaRoot, CaSubordinate, VisualStudio2013 and all domain roles are also supported on Azure.


$azurePublishingFile = '<PATH TO YOUR AZURE .publishsettings FILE>'
$azureDefaultLocation = 'North Europe'

#----------------------- CHANGING ANYTHING BEYOND THIS LINE SHOULD NOT BE REQUIRED ----------------------------------
#----------------------- + EXCEPT FOR THE LINES STARTING WITH: REMOVE THE COMMENT TO --------------------------------
#----------------------- + EXCEPT FOR THE LINES CONTAINING A PATH TO AN ISO OR APP   --------------------------------

$VerbosePreference = 'Continue'
$labSources = Get-LabSourcesLocation

New-LabDefinition -Name $labName
Add-LabAzureSubscription -Path $azurePublishingFile -DefaultLocationName $azureDefaultLocation
Add-LabVirtualNetworkDefinition -Name $labName -IpAddress -PrefixLength 24 -VirtualizationHost Azure
Add-LabDomainDefinition -Name -AdminUser install -AdminPassword Somepass1
Add-LabInstallationCredential -Username install -Password Somepass1

#defining default parameter values, as these ones are the same for all the machines
$PSDefaultParameterValues = @{
    'Add-LabMachineDefinition:Network' = $labName
    'Add-LabMachineDefinition:ToolsPath'= "$labSources\Tools"
    'Add-LabMachineDefinition:MemoryInMb' = 1024 #increasing this value can lead to higher costs
    'Add-LabMachineDefinition:Processors' = 2 #increasing this value can lead to higher costs
    'Add-LabMachineDefinition:VirtualizationHost' = 'Azure'
    'Add-LabMachineDefinition:IsDomainJoined' = $true
    'Add-LabMachineDefinition:DnsServer1' = ''
    'Add-LabMachineDefinition:DomainName' = ''


$role = Get-LabMachineRoleDefinition -Role RootDC -Properties @{ ForestFunctionalLevel = 'Win2003'; DomainFunctionalLevel = 'Win2003' }
Add-LabMachineDefinition -Name ContosoDC1 -IpAddress `
    -Roles $role -OperatingSystem 'Windows Server 2008 R2 SERVERDATACENTER'

$role = Get-LabMachineRoleDefinition -Role DC
Add-LabMachineDefinition -Name ContosoDC2 -IpAddress `
    -Roles $roles -OperatingSystem 'Windows Server 2008 R2 SERVERDATACENTER'

Add-LabDiskDefinition -Name ExchData1 -DiskSizeInGb 100
Add-LabDiskDefinition -Name ExchData2 -DiskSizeInGb 100

$role = Get-LabMachineRoleDefinition -Role Exchange2013 -Properties @{ OrganizationName = 'ExOrg' }
Add-LabMachineDefinition -Name ContosoEx1 -IpAddress -Processors 4 `
    -DiskName ExchData1 -OperatingSystem 'Windows Server 2012 R2 SERVERDATACENTER' -Roles $role

Add-LabMachineDefinition -Name ContosoEx2 -IpAddress -Processors 4 `
    -DiskName ExchData2 -OperatingSystem 'Windows Server 2012 R2 SERVERDATACENTER' -Roles $role

Add-LabMachineDefinition -Name ContosoSrv1 -IpAddress `
    -OperatingSystem 'Windows Server 2012 R2 SERVERDATACENTER'

Export-LabDefinition -Force -ExportDefaultUnattendedXml
Import-Lab -Path (Get-LabDefinition).LabFilePath -NoValidation

Install-Lab -NetworkSwitches -BaseImages -VMs
Install-Lab -Domains
Install-Lab -Exchange2013

Start-LabVM -All -Wait

Install-LabWindowsFeature -ComputerName ContosoSrv1 -FeatureName RSAT

Stop-LabVM -All -Wait

Does this work for you?
May 4, 2015 at 7:57 PM
Edited May 4, 2015 at 7:58 PM
Reduced script to a single DC and a single Exchange server. Result:

Setting up the lab took 03 hours, 33 minutes and 14 seconds

Maybe that is just the exchange installation taking a long while?

A few comments

"timed out" transfering - takes an excruciatingly long time to transfer files. Had to comment out 'Add-LabMachineDefinition:ToolsPath'= "$labSources\Tools" # timeout on transfering tools

Some warnings:

WARNING: Azure does not support statically configured DNS Servers. This setting will be ignored. The DNS server must be configured on the network

WARNING: VNetName, DnsSettings, DeploymentLabel or DeploymentName Name can only be specified on new deployments.

When running Remove-lab:

storage account is not removed by Remove-lab

Failed to remove the virtual network. Maybe change code to retry a few times.

_VERBOSE: Remove-LWAzureNetworkSwitch Entering... (Name=Demo1)
Set-AzureVNetConfig : BadRequest : An error occurred when setting the network configuration: The virtual network Demo1 is currently in use..
At C:\Users\Anders\Documents\WindowsPowerShell\Modules\AutomatedLabWorker\AutomatedLabAzureWorkerNetwork.psm1:103 char:12
  • $result = Set-AzureVNetConfig -ConfigurationPath $tempFile
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    • CategoryInfo : CloseError: (:) [Set-AzureVNetConfig], CloudException
    • FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS.SetAzureVNetConfigCommand_
Trying to remove disk fails everytime for obvious reasons

_VERBOSE: Removing disk '(ExchData1.vhdx.Name)'
Remove-Item : Cannot find path 'H:\AutomatedLab-VMs\Disks\ExchData1.vhdx' because it does not exist.
At C:\Users\Anders\Documents\WindowsPowerShell\Modules\AutomatedLab\AutomatedLab.psm1:715 char:7
  • Remove-Item -Path $disk.Path
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    • CategoryInfo : ObjectNotFound: (H:\AutomatedLab-VMs\Disks\ExchData1.vhdx:String) [Remove-Item], ItemNotFoundException
    • FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.RemoveItemCommand_

Have you considered the use of affinity groups (also makes it easier to distinguish labs)

installing ex. System Center from ISO that requires an MSDN subscription. How do you propose to get around this? I have used Azure File Storage for this. First copy the ISO to Azure File Storage, then mount the file storage using the SMB protocol.

Need a DNS for Internet lookups. Can you just do 'Add-LabMachineDefinition:DnsServer2' = ''
May 5, 2015 at 8:50 PM
Getting a new error recently. Seems abit random which dll is "missing. If I run Add-LabAzureSubscription a second time it doesn't complain

VERBOSE: Add-LabAzureSubscription Entering... (Path=E:\BizSpark-5-4-2015-credentials.publishsettings,DefaultLocationName=North Europe)
VERBOSE: Loading module from path 'C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ServiceManagement\Azure.\Services\Microsoft.WindowsAzure.Commands.dll'.
VERBOSE: Loading module from path 'C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ServiceManagement\Azure.\Automation\Microsoft.Azure.Commands.Automation.dll'.
VERBOSE: Loading module from path 'C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ServiceManagement\Azure.\TrafficManager\Microsoft.WindowsAzure.Commands.TrafficManager.dll'.
VERBOSE: Loading module from path 'C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ServiceManagement\Azure.\Services\Microsoft.WindowsAzure.Commands.Profile.dll'.
VERBOSE: Loading module from path 'C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ServiceManagement\Azure.\Compute\Microsoft.WindowsAzure.Commands.ServiceManagement.dll'.
VERBOSE: Loading module from path 'C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ServiceManagement\Azure.\Sql\Microsoft.WindowsAzure.Commands.SqlDatabase.dll'.
VERBOSE: Loading module from path 'C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ServiceManagement\Azure.\Storage\Microsoft.WindowsAzure.Commands.Storage.dll'.
VERBOSE: Loading module from path 'C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ServiceManagement\Azure.\ManagedCache\Microsoft.Azure.Commands.ManagedCache.dll'.
VERBOSE: Loading module from path 'C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ServiceManagement\Azure.\HDInsight\Microsoft.WindowsAzure.Commands.HDInsight.dll'.
VERBOSE: Loading module from path 'C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ServiceManagement\Azure.\Network\Microsoft.WindowsAzure.Commands.ServiceManagement.Network.dll'.
VERBOSE: Loading module from path 'C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ServiceManagement\Azure.\StorSimple\Microsoft.WindowsAzure.Commands.StorSimple.dll'.
VERBOSE: Loading module from path 'C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ServiceManagement\Azure.\RemoteApp\Microsoft.Azure.Commands.RemoteApp.dll'.
VERBOSE: Loading module from path 'C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ServiceManagement\Azure.\RecoveryServices\Microsoft.Azure.Commands.RecoveryServices.dll'.
VERBOSE: Get-LabDefinition Entering... )
New-Object : Exception calling ".ctor" with "0" argument(s): "Could not load file or assembly 'Microsoft.WindowsAzure.Commands.Common, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its depende
ncies. The system cannot find the file specified."
At C:\Users\Anders\Documents\WindowsPowerShell\Modules\AutomatedLab\AutomatedLabAzure.psm1:62 char:31
  • $script:lab.AzureSettings = New-Object AutomatedLab.AzureSettings
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    • CategoryInfo : InvalidOperation: (:) [New-Object], MethodInvocationException
    • FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand
After it seemingly loads the assembly the second time around I am getting another error from Add-LabAzureSubscription which I am not sure what to make of. These errors are from a recent checkout where I added a few things to continue working on Install-LabServiceManager2012

Cannot convert argument "collection", with value: "Microsoft.WindowsAzure.Commands.ServiceManagement.Model.LocationsContext[]", for "AddRange" to type "System.Collections.Generic.IEnumerable1[Microsoft.WindowsAzure.Commands
.ServiceManagement.Model.LocationsContext]": "Cannot convert the "Microsoft.WindowsAzure.Commands.ServiceManagement.Model.LocationsContext[]" value of type "Microsoft.WindowsAzure.Commands.ServiceManagement.Model.LocationsCo
ntext[]" to type "System.Collections.Generic.IEnumerable
At C:\Users\Anders\Documents\WindowsPowerShell\Modules\AutomatedLab\AutomatedLabAzure.psm1:72 char:125
  • ... onsContext[]]@(Get-AzureLocation))
  • ~~~~~~~~~~~~~~~~~
    • CategoryInfo : NotSpecified: (:) [], MethodException
    • FullyQualifiedErrorId : MethodArgumentConversionInvalidCastArgument