Featured image of post PowerShell Desired State Configuration

PowerShell Desired State Configuration

Use PowerShell Desired State Configuration to configure your system.

It’s always been an huge task to reinstall, reconfigure a new PC or migrating from a old PC. Downloading all the data and installing all the applications, it takes forever, and on top of that trying to update all. Many many many years back I worked at K2 and we had to build automated VM Ware machines. This was in the days before devops, ALM etc.. The machines would boot from the network, install Windows and install MOSS , pull down configuration and run automated tests. I believe the term is called pixiboot, it was cutting edge back then, and we got it working with plenty of scripts and custom dev..

Fastforward a bit, and Chocolatey came out, and I used it extensivly (I still do), and then Microsoft brough out WinGet. Digging into WinGet I could see how you can automate your installation of applications and set the state of Windows. It’s awesome, like Ansible but for Windows.

With PowerShell Desired State Configuration (DSC) you can have an YAML config file with different modules, that will either install applications, configure windows or even perform tasks like downloading from Git, setting Windows settings etc. This is really awesome to have your configuration in source control and run a command to update and configure your system to your needs.

I’ve started with the basic WinGet config file that will install the applications I need and use everyday.

# yaml-language-server: $schema=https://aka.ms/configuration-dsc-schema/0.2
properties:
  resources:
    - resource: Microsoft.WinGet.DSC/WinGetPackage
      id: BlenderFoundation.Blender
      directives:
        description: Install Blender
        allowPrerelease: true
      settings:
        id: "BlenderFoundation.Blender"
        source: winget
 configurationVersion: 0.2.0

List of applications to install

Applications can be installed from multiple sources like GIT, WinGet, Windows Store etc.. To get a list of applications, the ID and the location, you can run the below WinGet command

winget search "package"
eg.. winget search OBS

Example output for winget search OBS:

Name Id Version Match Source
OBS Studio XPFFH613W8V6LV Unknown msstore
OBS Studio OBSProject.OBSStudio 31.0.4 Moniker: obs winget

As you can see there’s is multiple version, to it is best to make use of the Id to download the specific version.

Where to from here

Create an applications.winget file, copy the above example and change the Id to OBSProject.OBSStudio. Once you have configured your applications.winget file you can apply the changes by simple running

winget configure .\applications.winget

What’s Next

This post is all made with version 2 of DSC, Microsoft just released version 3, that’s not depended on PowerShell, and is cross platform and you can create custom scripts for it. I’m still looking into that, and see what else I can do. But for now, I’m happy to just run a PowerShell command and install my applications, configure Windows and apply changes.

You can view my Github DSC resources by visiting https://github.com/mwolfaardt/dsc

References

Easily setup dev environments with WinGet and Microsoft DSC V3 | DEM572

Winget Collection

Microsoft Learn

PowerShell Gallery

DSC Community

Dsccommunity/ComputerManagementDsc

DSC Community

Winget Package Manifests

Winget DSC Example : Windows Settings

Getting Started with DSC

DSC PowerShell Examples

Built with Hugo
Theme Stack designed by Jimmy