MDR

MDR

Wednesday, August 1, 2012

PowerShell Gotcha

I've been playing around a lot with PowerShell recently, as I've been doing mostly System Administration work in a Windows environment. I have a script that I use to check the servers I'm responsible for, and generate a HTML report from the results.

I decided to add some jQuery to do a bit of client side processing on the report, that's when I ran into this little gotcha, escaping characters in a string. Like PHP, PowerShell uses the dollar sign "$" at the beginning of variable names, no problem, I'm used to that. In PHP if you want to use "$" in a string without it being interpreted as a variable, you simply escape it with a backslash, like so: "\$". Not so in PowerShell, you have to use the back-tick character "`" (on U.S. style keyboards this is located under the tilde, "~", to the left of the number 1. So your escaped string would look like: "`$".

Just a little something to keep in mind.

No comments:

Post a Comment