Free Consultation

Azure Automation State Configuration

Azure Automation State Configuration
Today I’d like to tell you a little about Azure Automation State Configuration (AASC). But before we can go into details of AASC, you should know what Desired State Configuration (DSC) is. Desired State Configuration is a management platform in PowerShell that enables you to manage your IT and development infrastructure with configuration as a code.
If you’d like to know more about Windows PowerShell Desired State Configuration, click here.


Azure Automation State Configuration

Azure Automation State Configuration is a very similar service to DSC, but more can be achieved AASC. DSC in Azure allows you to write, manage and compile configurations, import and assign configurations to targets servers. The most important feature is that all this runs in the cloud! I’ve provisioned many IT infrastructures and my biggest mistake was not using the PowerShell automation. Of course, I’ve used PowerShell scripts, but not to build an image of the machine with all services and additional software required.

Since I work mostly with Azure, I use Azure Automation whenever I can. One of the examples of my automation in Azure was preparing configuration for the virtual machines. VMs were running in Azure with specific files on the disk and with agents installed on them. You can do it manually on every server, but why go to this much trouble? It’s easier to use Automation 🙂

Let’s imagine you have a few servers in your environment that you want to add to your OMS and would like to copy some files from your Storage Accounts to a specific path on the servers.

Azure Automation State ConfigurationFirst, we need to create an Azure Automation Account on our Azure subscription. Then let’s upload files to our Storage Account container. I assume you have a virtual machine running Windows 2016 and OMS workspace. If not, you need to get it. Before we run DSC on our server, we need to prepare some configuration which will have all the information about the target configuration for the server.
Our goal is to copy files from a Storage Account to the server and add the server to the OMS Workspace using our configuration.

You can write the configuration using Visual Studio Code, Notepad, Notepad++ or use your favourite text editor.
Usually, I use Visual Studio Code for this. Configuration is a PowerShell file with .ps1 extension.
The important thing here is to remember that the name of the configuration must be the same as the name of the file.

This is how the configuration will look like:

Configuration blog-automation {

Import-DscResource -ModuleName xPSDesiredStateConfiguration
Import-DscResource -ModuleName PSDesiredStateConfiguration

$OmsWorkspaceId = “26106895-xxxxx40cd-8360-5eb389f8ab7d”
$OmsWorkspaceKey = “xxxxxxxxxZBQwuMmITOH9fDXieqIdhw9eW3mxWdilhoXqy8JXTt/4cWy4wL0SL9LA1ShIglmoy6m55K4qkeJA==”

$importantfile = “C:\blog\importantfile.txt”
$OMSAgent = “C:\blog\MMASetup-AMD64.exe”

Node localhost

xRemoteFile ImportanFile {
Uri = “”
DestinationPath = $importantfile

xRemoteFile OMSAgent {
Uri = “”
DestinationPath = $OMSAgent

Package MMA {
Ensure = “Present”
Path = $OMSAgent
Name = “Microsoft Monitoring Agent”
ProductId = “EE0183F4-3BF8-4EC8-8F7C-44D3BBE6FDF0”
Arguments = ‘/C:”setup.exe /qn ADD_OPINSIGHTS_WORKSPACE=1 OPINSIGHTS_WORKSPACE_ID=’ + $OmsWorkspaceId + ‘ OPINSIGHTS_WORKSPACE_KEY=’ + $OmsWorkspaceKey + ‘ AcceptEndUserLicenseAgreement=1″‘
DependsOn = “[xRemoteFile]OMSAgent”

Azure Automation State Configuration
As you can see, there are two links to the Storage Account in the script. One directs to the important file which we want to copy and the second one is the OMS Agent, which we want to install using DSC. These files need to be uploaded before we run the Azure DSC configuration on our server.

Files are in place. Now is time to save the configuration as blog-automation.ps1 and upload to the Azure Automation DSC. After the upload, we go to our configuration and we need to compile it.


Before we compile our config, we need to add modules to Automation Account which we are using in the configuration. In my case it is xPSDesiredStateConfiguration. If you forget to do it, you will get a notification that the module is missing and it won’t compile it.

Azure Automation State Configuration

When you click compile, the configuration’s status will be queued. It will take a few seconds, maybe even minutes, and then information should appear that your configuration is Completed.

Azure Automation State Configuration

Finally, it’s time to assign the configuration to our node.

Azure Automation State Configuration

Azure Automation State Configuration

After that, there is nothing else to do other than wait for the results of our configuration – in our case, it means the VM will appear in OMS console and files will appear on disk C:\ of the virtual machine.

Azure Automation State Configuration

Azure Automation State Configuration

The example presented was one of the easiest. But think about it- if you have a hundred or more virtual machines, would you want to go one by one installing the software? Sure you don’t. Work smart and use automation!