Desired State Configuration keeps your servers correctly configured using a simple PowerShell script. In this video, Sharon shows you how to apply the DSC extension to your virtual machines.
- [Instructor] Desired State Configuration, or DSC, was introduced for Server 2012 R2, back in 2013. It's an automation mechanism to ensure your servers, either physical or virtual, always have the same configuration applied to them. Here's an example of DSC. Let's imagine I have setup a server exactly the way I want it, then someone comes along and changes a setting, which messes up my configuration. This could have undesired consequences. Instead of me now trying to figure out what changed, I can use DSC and the server will automatically correct itself based on my scripts that I've applied to it.
We can also use virtual machine extensions to configure our virtual machines. There are several extensions already available to you, or you can use custom scripts. Examples of configuration settings that you can manage through DSC include server roles and features, registry settings, files and directories, packages, environment variables, and deploying new software. DSC is a great automation tool, but it is out of scope for this course. If you would like more information, I have included a link to an excellent MVA session.
There are two ways you can apply DSC to your virtual machines. You can use an automation account, or we can do it through the virtual machine extensions. Our demo today will focus on the virtual machine extension method. We're looking at our Proddata resource group which has two front-end web servers. These web servers have not been configured with IIS as of yet. I'm going to use DSC to configure IIS on Web1, and then I'm going to use a custom script extension to again apply IIS to Web2.
Then I'm going to go ahead and apply the BgInfo extension to Web2 as well. I'm going to go ahead and show you Web1 and Web2. The virtual machines are already up and running, and I've already connected to them. As we can see here, we're on Web1, and we do not have IIS installed, but we do have the BgInfo extension installed. I'm going to flip over to Web2. Again IIS is not installed, and I do not have BgInfo. Before I start configuring the extensions, I actually want to show you what the scripts look like. To do so, I'm going to go ahead and launch ISE.
I already have our scripts preconfigured for us. I'm going to go ahead, Open the script in our Exercise Files, and it just so happens to be DSC. We'll notice here, what we're going to do is install IIS. The node or the computer name will be localhost, and this is a very, very simple script of installing IIS. It will check to see if IIS is already installed. If not, it will install it. You could expand on this. You could create scripts that have your virtual machines join a domain. You could rename them, you can install software, you could install other roles, but for our demonstration, I'm just going to do IIS.
I'm going to go ahead and close that. I'm going to click Add. You'll notice that we have several extensions available to us. You're going to want to scroll down until you find PowerShell Desired State Configuration, and then click Create. Now what I showed you was the script, the ps1 file. We actually have to publish that to a ZIP file. Within the ZIP file, I have the script, and now I need to input the Module-qualified Name of the Configuration, and this will be the name of the script itself, which we saw, which was DSC, and then the name of the configuration, which is IISInstall.
If I had any configuration arguments, I would enter them here. If I had a file defining the configuration data, I would enter that here. The Windows Management Framework, or WMF Version, I'm going to go with the latest, but there are different versions you can choose from. Again, refer to the documentation for more details. I'm going to go ahead and enable Collection, and I know for this extension I am going to have to use Version 2.17. If there is a Minor Version Upgrade, I will go ahead and upgrade it, and click OK.
I'm going to warn you ahead of time, it could take up to ten minutes for your extensions to be provisioned, so keep that in mind. The extension is being applied to the virtual machine. It's going to check the virtual machine to see if IIS is present. Because it's not, it's going to go ahead and install IIS. This will require reboot, and this will take, like I said, some time. We can now see PowerShell DSC has been successfully provisioned, and let's go take a look at our virtual machine, Web1.
I have the Web1 remote desktop connection in my Exercise Files folder. I'm going to go ahead and connect to it, and IIS has been installed for us. You can see the benefit of using DSC. If for some reason IIS had become uninstalled, the next time the virtual machine rebooted, IIS would be installed again. By using PowerShell scripts, you can easily ensure that all of your machines have the same configuration every single time they reboot.
- Creating a Windows virtual machine
- Deploying a Linux virtual machine
- Using PowerShell for creating a Windows VM
- Configuring extensions
- Enabling remote debugging
- Configuring shared storage
- Configuring disk storage
- Working with Azure Disk Encryption
- Monitoring and creating VM alerts
- Configuring diagnostic and storage monitoring
- Creating availability sets
- Combining the load balancer with availability sets
- Scaling up and scaling down VM sizes
- Creating and modifying VM scale sets