PowerShell: remove or replace quote marks from variable

Pat picture Pat · Feb 11, 2013 · Viewed 84.7k times · Source

I'm using Get-EventLog to set a variable, and then setting another variable with the event ID description. I then use blat.exe to email this information to a group.

The description contains quotation marks. The quotation marks are causing blat to exit with error.

Is there a way to remove the quotes from the event.Message and replace them with a space or something?

Answer

Musaab Al-Okaidi picture Musaab Al-Okaidi · Feb 11, 2013

If the variable is a String object then you can do the following:

$Variable.Replace("`"","")