xWebVirtualDirectory Mandatory WebApplication Parameter Blocks VD Creation

Searching through the vast online realm that we call the internet, your find a new stream of PowerShell Desired State Configuration (DSC) resources being created daily to configure anything from Active Directory to the Chrome browser. Microsoft the creator of PowerShell DSC publish their own DSC resource kit, as well as encouraging the community to create their own resources.

Working a lot with Microsofts xWebVirtualDirectory resource (part of the xWebAdministrator module) recently lead me to stumble upon what I believe is a design flaw in the resource. This design flaw was that the WebApplication parameter was mandatory though didn’t allow empty or null strings which meant I was unable to create virtual directories that weren’t sat under a web application. Running the cmdlet New-WebVirtualDirectory directly also confirmed to myself that the WebApplication parameter wasn’t required though did allow empty strings to be used if declared.

After spending sometime unsuccessfully trying to work out a way to pass a null or empty string as the WebApplication parameter I decided to explorer the code behind the xWebVirtualDirectory resource where I discovered this was because the mandatory attribute was used without allowing empty strings. I have therefore had to modify this behaviour for my usage of the resource so wanted to share my modified version.

Below you can find a link to the modified version of the resources psm1 file on my Github, alternatively, you can search through your own copy of the resources psm1 file and add the [AllowEmtpyString()] attitude to every $WebApplication or $Application parameter.


Posted in DevOps, DevOps with : PowerShell, DSC