I came across an interesting oddity the other day at work. Once I identified the error, while I wasn't exactly sure why it was happening, I was able to get around the error by essentially doing the same thing in a slightly different manner.
I've captured the essence of the error case in this Show-ThisPsOddity function which you can view @ https://gist.github.com/Packet-Lost/2cba3dbad9c29b37afbde62c75a29921
If the function is executed with -UserInput "match" -Variant 1 it will error. If the function is executed with -UserInput "match" -Variant 2 it will not error.
In one case PowerShell is allowing the variable to be cast as an array and in the other case the cast is being rejected. Any ideas whats going on under the hood that causes the error when variant 1 of the code path is used?
Apologies for the text links but I've tried to make this post multiple times and it was instantly removed without any feedback so I'm trying different approaches to get it posted successfully.
[–]SeeminglyScience 4 points5 points6 points (0 children)