DSCParser – Analyze your PowerShell DSC Scripts

For each DSC project I am involved in, there’s been a point where I had the need to figure out a way to programmatically determine what is contained within my DSC script. As an example, one of the side projects I am working on is something called VisualDSC, which allows you to load a .ps1 Desired State Configuration file within Visio, and have it generate a diagram representing your configuration with the data linked onto the various shapes. In order to do this properly however, I need a way to read what is inside my DSC script and interpret its elements; a way that is better than parsing text within the configuration, which is what I had to resolve to doing up until now.

While on a plane back from the mothership in Redmond, I decided to finally bite the bullet. Thanks to my colleague Nitin Gupta from the PowerShell product Group who gave my some pointers, I was able to build a fairly simple module that lets us parse existing .ps1 DSC scripts into PSObjects. This allows us to analyze the content of our PowerShell Scripts for anomalies or to extract valuable information from it. The module ca be installed directly from the gallery by running the command below or by downloading it from its official GitHub repository at https://GitHub.com/Microsoft/DSCParser.

Install-Module DSCParser


The module currently exposes a single method, named ConvertTo-DSCObject and which takes the path to our DSC .ps1 file. This allows us to do things like, figure out how many instances of a specific resource we have defined in our scripts:

$DSCContent = ConvertTo-DSCObject -Path "C:\DSC\SPFarmConfig.ps1"
$SPWebAppPermissions = $DSCContent | Where-Object { $_.ResourceName -eq "SPWebAppPermissions" }

DSC Script to retrieve WebApp Permissions

We are still in the early stages of the module, and everyone is encouraged to submit feedback by using the Issues tab of the GitHub repository.

Leave a Reply

Your email address will not be published. Required fields are marked *