PowerShell to Power Platform Solution Components

Quick snippet, PowerShell to Power Platform Solution Components, to illustrate how to list or iterate through your solution components stored in an Azure DevOps repository using a Power Shell script.

If you are using Azure DevOps to manage your Power Platform project, and are following good practices, you are most likely using the Power Platform Build Tools.

What these tools allow you to do is to configure a Pipeline in Azure DevOps to export your Solutions from a DEV environment, unpack them and store the configuration as if it was code.

Unpacking the solution components is useful to keep track of the changes you make during your developments, as well as to see the history of those changes.

PowerShell to Power Platform Solution Components
The image above shows the contents in the repository, of a solution unpacked.

What can this be used for?

When you extract and save your solutions in a source control repository, the amount of information you have at hand in the shape of files is enormous. This opens up the door to analyse the data and for example:

  • Auto-generate documentation from configuration.
  • Check or enforce good practices.
  • Retro-feed it to Azure DevOps and create or update Work Items.

You can use the script presented here to configure a Pipeline in Azure DevOps and perform any of the above.

Solution Components

When you unpack a solution, the list of folders and files you get follow a precise structure. The contents describe all the properties and code of your solution.

There is one particular file that we should pay attention to. Is called the Solutions.xml file.

This is an Xml that has an index with all the items in the solution, along with their type.

To know what each solution type code is, check the reference.

For example, on the capture above, we can see we have a few Tables with type 1, a couple classic Workflows, with type 29, 91 is a Plugin Assembly, 92 is a Plugin Step, and 300 is a Canvas App.

Code Explained

The code below does two things: First, it opens and the Solution Xml File and second, selects the Xml node values that contain the solution components. Couldn’t be simpler.

https://gist.github.com/crisfervil/c5b10df2000c2c0e08c88ed22badb458#file-powershell-to-power-platform-solution-components-basic-ps1

1. First, we let the script know the path to the folder where we keep the unpacked solutions.

2. You could build a script that iterates through multiple folders, and reads the contents of each solution, but for simplicity, this scripts reads the contents of only one solution, which schema name is specified in this point.

3. With the information above we construct the path of the Solution.xml file, so we can access it.

4. Xpath is a language that allows us to query Xml files. Most platforms and languages support accessing Xml files using this query language. In this script we are using a very simple one. What is expression is asking is: Give me all the RootComponent nodes in the Xml file that are under another node called RootComponents, which is under another node called SolutionManifest which is under the root node called ImportExportXml.

5. Next, we have the Select-Xml cmdlet that queries the Xml file using the Xpath provided. Now we can iterate through the results, and do something with this information.

6. Display the node information in the screen.

Bonus

If you want to go a little bit further, check out the example below.

Is slightly more advanced, and it shows how to solve a couple of problems you’ll find if you use this code.

The step #5 shows how to map the Solution Component type codes to a descriptive text.

Step #6 solves the issue with the Solution Component names. If you are trying to get the name of any component, you have to know that each one has its own properties in its own separated file.
Depending on the component type, the file is located in a different place.
Is not rocket science, and as you will see, it is solved in less than 5 lines of code.

https://gist.github.com/crisfervil/33d801765380c501f1d4b32eb750e0b4#file-powershell-to-power-platform-solution-components-advanced-ps1

Conclusion

The code above tries to demonstrate the steps towards an idea. From here you can start building interesting things, as we will see in future posts.

This is a basic tutorial PowerShell to Power Platform Solution Components that I plan to reference in future articles.

I hope you find it useful. If you have any comments or queries, please leave them below. And be update in our blog.

Photo by Luca Bravo on Unsplash

Subscribe to our newsletter