Not all characters are created the same

image

I was up late doing some PowerShell coding to set alerts on mailboxes in Microsoft 365 and I had everything working nicely as you can see above. At this stage I was just using the standard PowerShell ISE to execute the code.

I had also been updating the code with Visual Studio Code so I could then push it up to my GitHub repositories. Just before call it quits I now ran the scripts directly from the command prompt which is where the Visual Studio Code version had been saved. In essence, at the command prompt, I ran:

.\o365-mx-alert-set.ps1

When I did this I now received the following error:

image

How is that possible? The code on the disk via Visual Studio Code is exactly the same as the code I had been working with directly in the PowerShell ISE. I don’t understand why I am getting this error.

I spent quite a long time trying to resolve the issue but to no avail. Out of desperation, the following morning,  I contacted PowerShell guru Elliot Munro from GITS for help.

Long story short, Elliot pointed out that from the error it appeared to be:

an issue with the em dash character, the one in front of AuditDelegate is a different dash compared to the other parameters ( – instead of – ). I guess running it from the command line doesn’t automatically convert it to the standard dash like ISE does.

BINGO we have a winner. Changing the dash to the “right” one fixed that problem immediately! Elliot, you are a legend and life saver.

image

As you can see from the above, there is very slight difference in the dash at front of the parameter. The top one is the one that works, the bottom one is the one that causes the error. No much in it eh? However, that was all it took to waste a few hours of my time late at night looking for an answer.

Hopefully, this article get found by others who may have the same issue and error in PowerShell and I can ‘pay forward’ Elliot’s assistance.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s