Chef/PowerShell Quick Tip: use the right Slash

Wanted to share a quick tip with you today regarding using PowerShell from within Chef.  More specifically, using the dsc_resource to run PowerShell script.  I routinely use this resource to run PowerShell on Windows nodes through Chef.  In this case, the test script always returned false.  The test was a simple test-path call against a directory and even after I knew the folder was created, the test continued to return false.

After much testing I found the only difference between the test script that worked and this one was the type of slash I was using.  The problematic test was using back slashes and the others were all using forward slashes.

Notice the differences on line 5 of each sample.  The only difference is the type of slash.  Changing to forward slashes fixed the issue.

I ended up spending hours on this.  Please learn from my mistakes.  I suspect this is likely a problem in other areas where you embed PowerShell within Chef but haven’t tested this further.

2 thoughts on “Chef/PowerShell Quick Tip: use the right Slash”

Leave a Reply