Last Update: Sep 04, 2024 | Published: Aug 02, 2016
In today’s Ask the Admin, I’ll show you how to create an Azure Automation account, upload and compile a DSC configuration, and on board an Azure VM.
In Introduction to Azure Automation Desired State Configuration on the Petri IT Knowledgebase, I explained how Azure Automation Desired State Configuration (DSC) relieves organizations of some of the infrastructure requirements of PowerShell DSC, along with other advantages, including controlling who can access DSC configurations, assign them to nodes, and check node configuration compliance. Today we’re going to get down to business and configure Azure Automation DSC.
Before we can test out Azure Automation DSC, we’ll need a DSC script. For the purposes of this demonstration, we’ll use a basic script that checks for the presence of a text file (test.txt). If the file is not present, it’s created.
Configuration FileResourceDemo { Node "localhost" { File CreateFile { DestinationPath = 'C:Test.txt' Ensure = "Present" Contents = 'Hello World!' } } }
You can copy the above code into Notepad or the Windows PowerShell ISE. Save the script to your PC as TestDSC.ps1
Azure Automation DSC requires an Azure Automation account in addition to the Microsoft account associated with your subscription. If you don’t already have an Azure Automation account, create one using the steps below.
You’ll need to wait a few minutes for the accounted to be created. To check if the account has been created successfully:
Now that we have created an Azure Automation account, let’s add the DSC configuration script that we created earlier to Azure.
Again, we’ll need to wait a few minutes for DSC script to be compiled into a MOF file.
The final step is to on board a VM (node) and assign the DSC configuration. Note that it’s also possible to on board VMs hosted by cloud providers other than Microsoft, and on premise servers.
Adding the node can take up to ten minutes. It could take even more time for the configuration to apply to the node(s), depending on the refresh and configuration mode frequencies set. But you should connect to the node using RDP and check if test.txt was created.