PowerShell Desired State Configuration — Azure

Sachin Modi
3 min readJan 7, 2021

Similar to Custom Script Extensions, if you want to automate the software installation onto virtual machine we can use PowerShell desired state configuration. The only difference between custom script extensions and PowerShell desired state configuration is that PowerShell desired state configuration can combine with other service called Azure Automation so if anyone uninstall the already installed software in that VM, it will make sure to reinstall that software.

You would need to upload below 2 configuration file in your azure storage account.

webconfig data file psd1
PowerShell Desired state configuration File.ps1

You would need to zip the PowerShell desired state configuration before uploading onto azure storage account.

Now go to Azure Portal → Virtual Machine → Select your newly created Virtual Machine → click on Extensions → Add → chose PowerShell Desired State Configuration → click on create

PowerShell Desired State Configuration

Once configurations are applied you will see the status as succeeded.

PowerShell Desired State Configuration status

Now if you go to the public address of your virtual machine in browser you will see the IIS page in browser.

IIS Web Page

If you are getting any error in your browser then make sure that you have added the inbound rule for port 80. This can be found under networking section Inbound port rules.

Inbound Port Rule

Now to enable the Automation with PDSC we would need to create an automation account in Azure portal.

Now got to newly created automation account → State Configuration → Configuration → Add

and then upload the below ps1 file.

webserver.ps1

once the file is uploaded click on file and then click on compile.

Once the configuration has compiled you can add the node as part of this automation. You can select the VM on which you want to apply this state configuration.

Now if you go to the public address of your virtual machine in browser you will see the IIS page in browser.

IIS Web Page

You can go ahead an uninstall the IIS from server and then go to public address of your VM in browser you can still be able to access the IIS page.

Node added in State Configuration

Please follow me in LinkedIn :

https://www.linkedin.com/in/sachin-modi-%E2%98%81-6b16b947/

--

--