We live in a world these days where copy & paste is the shortest path to winning. In a world of Stack Overflow and Thwack and all those other sources of awesome content, it’s easy to find something you like, fire up a SAM template with a fresh PowerShell component and then paste the content in there. Sometimes it doesn’t go so well and when it doesn’t, it can be maddening.
Let’s take this email with some helpful SolarWinds API code for example,
It looks good, right? Add the snapin, build the connection, run the query, get the results. Nothing could be easier. But when you try to run it in PowerShell, you get some pretty confusing results:
The error we get is on
Get-SwisData which is a little maddening since that’s the very first command we tried to run. It’s simple and there’s no obvious issue with it. You fire up a PowerShell window and try it to make sure you have the syntax right and all goes well. So… what gives?
If you look closely, you can see that Outlook has helpfully converted your quotes to “smart quotes” which are a bit curvier:
This is going to break your code because it’s expecting regular quotes ” instead of smart quotes that wound up in its place. It’s taken some practice, but having this bite me several times in the past I’ve taken to very carefully typing code and keeping an eye on these automatic changes which you can reverse by using undo (ctrl+z) like below:
If you’re not a fan of smart quotes and you’d rather just turn them off so they don’t muck up the works, you can do that by adjusting Outlook’s configuration:
That’s all there is to it! You’ll never have that problem bite you again.