Skip to content

Bootstrapping DSC into Windows Azure

Michael Washam edited this page Nov 26, 2013 · 5 revisions

Dependencies

These scripts have a dependency on the Windows Azure PowerShell Cmdlets.

Click here for instructions on setting up the WA PowerShell Cmdlets

Creating the DSC Pull Server

The following script will create a new Windows Server 2012 R2 Virtual Machine (Size small) in the Windows Azure subscription "opsgilitytraining" in the "mypullsvc" cloud service named "pullsrv".

$subscription = "opsgilitytraining"
$serviceName = "mypullsvc"
$vmNamePull = "pullsrv"
$vmSize = "Small" 
$Location = "West US"

.\create-pull-srv.ps1 -SubscriptionName $subscription -ServiceName $serviceName -Name $vmNamePull -Size $vmSize -Location $location

Once executed you will be prompted for the credentials for the local administrator account and password of the pull server.

Creating a DSC Configuration

Once the pull server is provisioned login to the virtual machine via Remote Desktop. Using File Explorer, open C:\DSCScript, right click on the WebFarmConfig script and select edit.

WebFarmConfig.ps1

. $PSScriptRoot\SetConfiguration.ps1

Configuration WebServer {
    param($node)
    node $node
    {
        WindowsFeature IIS
        {
            Ensure = "Present"
            Name = "Web-Server"
            IncludeAllSubFeature = $true
        }
    }
}
SetConfiguration -Configuration WebServer

This is a bare bones DSC configuration that you can use to validate your configuration. The SetConfiguration.ps1 script is included and provides the helper method SetConfiguration which executes the DSC configuration and generates the necessary .mof files for the pull server.

Execute the script

Execute the script by pressing F5 in the open ISE.

Two .mof files will be generated in the following folder: C:\Program Files\WindowsPowerShell\DscService\Configuration

This is the configuration that will be downloaded by clients specifying the same configuration name (WebServer) in the client script.

Creating a DSC Client Virtual Machine

You will be prompted for the local credentials for the virtual machine. If you would like to use the DSC file provider to deploy files to the clients it is advised to make these credentials the same as the pull server. Note: The virtual machine should be deployed into the same cloud service as the pull server.

$vmNameClient = "pullclient"
$configName = "WebServer"

.\create-pull-client.ps1 -SubscriptionName $subscription -ServiceName $serviceName -Name $vmNameClient -Size $vmSize -CertificatePath .\PSDSCPullServerCert.pfx -PullServer $vmNamePull -ConfigurationName $configName 

Checking the configuration

By default you will have to wait until the DSC configuration is applied to the client. The initial deployment is around 30 minutes.

OR

You can also login to the client and force the DSC consistency check by executing the following PowerShell commands.

Get-ScheduledTask "Consistency" | Start-ScheduledTask

Validation

To validate the configuration is applied to the pull client run:

Get-DscConfiguration

Note: I've noticed that even after forcing the consistency check it may take 3-5 minutes to apply depending on the configuration of course.