Looks like that trailing $ causes problems in PowerShell v2, even though it doesn’t actually cause any expansion to take place. It worked when I put a backtick before the $ (in a double-quoted string). In this case, though, single quotes are more appropriate anyway.
Ah, beat me to it. Ya, dug out a v2 VM and observed the same thing. Strikes me as a bug, which is obviously fixed, but a search in Connect didn’t turn anything up. Likely the team noticed it and fixed it internally for v3.
Anyway, Nithun, there’s a kind of “good practice” to use single quotes unless you explicitly need the feature of double quotes (variable replacement, escape characters, subexpressions), which helps avoid this problem (as Dave suggested).
Thank you so much Don and Dave for the inputs, I am very new to powershell.org and it was my first post here.
Feel so special and blessed to be a part of this.