Today I was very happy to find a neat solution to handle configuration data for a DSC configuration. I was facing the following challenge:
In a SharePoint DSC Configuration I want to reuse several SQL Aliases that are created during run time of the DSC configuration based on the configuration data.
In recent DSC setups my configuration did look like this:
and I created the SQL Alias with the following lines of code:
This far there was no struggle at all. Creating a SQL Alias with DSC is very straight forward, even if there is the need to create more than one.
The struggle got real the moment I had to reuse the Alias Name in SharePoint. How do I properly access the Alias? Do I iterate over all aliases again and filter or do I hard code the alias name or…? None of the before felt right.
My solutions is pretty simple: Why not change the array to another hash table – A hash table allows to access the data more easily. 🙂
Final challenge: How can I iterate over a hash table? A hash table object has two properties: keys and values:
So what changed in my SharePointDsc configuration part? Now I can address my SQL Alias properly without having any troubles: