AcloudA

[PowerShell] Create a DSC server on Azure

Posted by Florent Appointaire on August 12, 2019
Tags: ,


Today I’ll show you how to deploy a DSC server on Azure. This server will have the function of reference server, and will be the PULL server to store configurations.

To start, deploy a new server on Azure (Windows Server 2016 for me) and allow in the NSG, port 8080 and 443.

Install the following feature and the DSC module, with the following commands:

Install the following feature and the DSC module

Save the following script to configure your DSC server:

https://github.com/Flodu31/PowerShellDSC/blob/master/DSCPullServer.ps1

You can add a certificate and adapt ports. Execute it to generate the MOF configuration file for your server:

You can add a certificate and adapt ports

Launch the configuration of the server by executing the following command:

Launch the configuration of the server

To verify that the configuration has been applied correctly, navigate to the following URL on your server: http://localhost:8080/PSDSCPullServer.svc/

You’ll have something like that:

To verify that the configuration has been applied correctly, navigate to your server

We will now create the configuration for our server that will receive the installation of RSAT. Use the following script, by replacing the Computername and the OutputPath:

https://github.com/Flodu31/PowerShellDSC/blob/master/DeployRSATDSC.ps1

Execute it:

RSAT

A new MOF file appeared. It contains the configuration for your server. Because we will use this file for multiple server, from our pull server, we need to rename it. Use a GUID to make it easier:

Administrator

To allow target servers to be able to get files configurations, we need to copy files into C:\Program Files\WindowsPowerShell\DscService\Configuration. Use the following command to do this:

Administrator Copy item

To be sure of the origin of configuration files, we need to generate a checksum associated to our configuration:

We will now apply the configuration to our target server, to give the instruction to our server to download automatically the configuration file on our pull server. Download the following script:

https://github.com/Flodu31/PowerShellDSC/blob/master/DSCPullMode.ps1

Modify it with your ServerUrl from where you access it, the target IP address (connection is done with WinRM, so you need to configure and allow it) and the GUID that has been generated for the configuration file. Execute the script:

A new MOF file has been generated

A new MOF file has been generated.

Go now on the target client and verify with the following commands that the configuration has been applied correctly:

Get-DscLocalConfigurationManager

After 15 minutes, the client is downloading the MOF file and is applying it:

The client is downloading the MOF file

You can automate many installations with DSC, like the deployment of new IIS servers, Active Directory, SQL, etc.

Related materials:

Views All Time
1
Views Today
3
Return to all posts

How to connect to AWS EC2 Ubuntu Server instance via SSH and RDS
Connecting On-Premises Windows Servers to Azure Monitor