Azure – Configure Azure PowerShell Desired State Configuration (DSC) Using PoserShell
Hello Friends,
If you missed our following articles on Exam : Developing Microsoft Azure Solutions, Please have a look once here :
Azure – Deploying a Web App to Azure Virtual Machine with Web Deploy method
Azure – Remote debugging on an Azure VM
Azure – Azure Automation State Configuration
Azure – Configure Azure PowerShell Desired State Configuration (DSC) Through Azure Portal
Azure – Azure Resource Manager
In our last blog, we have seen How To Configure Azure PowerShell Desired State Configuration (DSC) Through Azure Portal. As we know, it is possible to configure Azure Automation State Configuration and Azure Powershell Desired State Configuration (DSC) using powershell as well. Today in this blog we will configure Azure powershell DSC using Powershell.
Prerequisites :
An Azure Resource Manager VM (not Classic) running Windows Server 2008 R2 or later. For this example we have created one VM “DSCSrvPowershel” in advance. As we can see in the following figure, we have verified that, currently IIS not installed/available with this VM. Our Azure powershell DSC, will install/configure the IIS on this server/Node for us.
Figure 1: Azure Certification 70-532 – IIS not available on this VM
Now we are ready to start with our first Azure DSC configuration using Powershell. We will go step by step in little detail with real time figures.
-
- Connect to your Azure portal dashboard using your subscription account. If you don’t have any subscription, in that case you can get trial Azure subscription with one-month of validity. Then you can connect to the azure portal dashboard as in following figure.
Figure 2: Azure Certification 70-532 – portal dashboard - We have created one VM ( DSCSrvPowershel ) with Window Server 2016 in advance, So that we have one fresh VM without any additionally configuration. As we can see in the following figure, here IIS has not been installed on the server and we are going to configure IIS by Azure DSC extension.
Figure 3: Azure Certification 70-532 – DSCSrvPowershel VM without IIS installer before running DSC Extension - Same as in our last blog, We have crated one DSC configuration in powershell, as shown in the following figure.
Figure 4: Azure Certification 70-532 – DSC ConfigurationSample Script 1 :configuration IIS { Node ("localhost") { WindowsFeature WebServer { Ensure = 'Present' Name = 'Web-Server' IncludeAllSubFeature = $true } } }
- Now we would use Publish-AzureRmVMDscConfiguration to uploads a Desired State Configuration (DSC) script to Azure blob storage.In this case it will upload our “ManasDscConfigByPowerShell.ps1” to Azure blob storage and store it as a zip file. Publish-AzureRmVMDscConfiguration is one of the new cmdlets in the Azure PowerShell SDK. We can use this powershell command with different parameters.
-
-
- Following are few important required parameters, which help, to be specific of the storage place.
- -ConfigurationPath :
Specifies the path of a file that contains one or more configurations. The file can be a Windows PowerShell script (.ps1) file or a Windows PowerShell module (.psm1) file. - -ResourceGroupName :
Specifies the name of the resource group that contains the storage account. - -StorageAccountName :
Specifies the Azure storage account name that is used to upload the configuration script to the container specified by the Container Name parameter.
-
Other than the above parameters, there are other optional parameters, we can specify as per requirement.
-
- In this following sample, I have passed my Azure Resource Group and Storage Account as parameters to the script.Sample Script 2 :
Publish-AzureRmVMDscConfiguration "C:\ByPowershell\ManasDSCConfigByPowerShell.ps1" -ResourceGroupName "ManasResource" -StorageAccountName "manasstandardstorage"
In the following figures, we can see it has created a zip file in our specified storage account.
Figure 5: Azure Certification 70-532 – Published Powershell DSC To Azure - We can go to the Azure portal and verify, if script has created a new windows-powershell-dsc Container under blob storage of the Storage account, we have provided as a parameter to the script. As we can see in the following figure, the script has also created the ManasDSCConfigByPowerShell.ps1.zip in that container.
Figure 6: Azure Certification 70-532 – Window-Powershell-DSC container
Figure 7: Azure Certification 70-532 – Zip file Under Container of blob storage - Now the time comes to apply the configurations to the Virtual Machine. To achieve that, We need to make use Set-AzureRmVMDscExtension Azure command.The Set-AzureRmVMDscExtension cmdlet configures the Windows PowerShell Desired State Configuration (DSC) extension on a virtual machine in a resource group.We can use this powershell command with different parameters.
-
-
- Following are few important required parameters with this commlet.
- -ResourceGroupName :
Specifies the name of the resource group of the virtual machine. - -VMName :
Specifies the name of the virtual machine where DSC extension handler is installed. - -ArchiveStorageAccountName :
Specifies the Azure storage account name that is used to download the ArchiveBlobName. - -ArchiveBlobName :
Specifies the name of the configuration file that was previously uploaded by the Publish-AzureRmVMDscConfiguration cmdlet. - -Version :
Specifies the version of the DSC extension that Set-AzureRmVMDscExtension applies the settings to.
-
Other than the above parameters, there are other optional parameters, we can specify as per requirement.
Sample Script 3 :
Set-AzureRmVmDscExtension -version 2.21 -ResourceGroupName "ManasResource" -VMName "DSCSrvPowershel" -ArchiveStorageAccountName "manasstandardstorage" -ArchiveBlobName ManasDSCConfigByPowerShell.ps1.zip -AutoUpdate:$true -ConfigurationName IIS -WmfVersion 5.0
In the following figures, we can see in the powershell ISE, it has successfully set\provisioned the Azure DSC configuration also , we can see the same in Azure portal under teh Extension of the selected VM.
Figure 8: Azure Certification 70-532 – provisioning DSC to VM
Figure 9: Azure Certification 70-532 – provisioning DSC to VM in Azure Portal -
- Now time comes, to check the actual result by login to the selected VM, to see, whether the required configuration (IIS configuration) has done successfully. As we can see in the following figure, the IIS configuration done successfully by the Azure Powershell DSC.
Figure 10: Azure Certification 70-532 – IIS Installed on VM
- Connect to your Azure portal dashboard using your subscription account. If you don’t have any subscription, in that case you can get trial Azure subscription with one-month of validity. Then you can connect to the azure portal dashboard as in following figure.
More Usefull References :
TechNet Gallery – resources for IT professionals
Introducing the Azure PowerShell DSC (Desired State Configuration) extension
Thanks for reading 🙂
Keep reading, share your thoughts, experiences. Feel free to contact us to discuss more. If you have any suggestion / feedback / doubt, you are most welcome.
Stay tuned on Knowledge-Junction, will come up with more such articles.
good one