Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PowerShell: remove or replace quote marks from variable

Tags:

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?

like image 523
Pat Avatar asked Feb 11 '13 16:02

Pat


People also ask

How do you replace double quotes in PowerShell?

Use the PowerShell String replace() method or replace operator to replace the double quotes in PowerShell with empty spaces or single quotes. e.g. $str.

What does @{} mean in PowerShell?

The Splatting Operator To create an array, we create a variable and assign the array. Arrays are noted by the "@" symbol.

How do you remove quotation marks from a string?

To remove double quotes from a string:Call the replace() method on the string. The replace method will replace each occurrence of a double quote with an empty string. The replace method will return a new string with all double quotes removed.


1 Answers

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

$Variable.Replace("`"","") 
like image 58
Musaab Al-Okaidi Avatar answered Sep 18 '22 09:09

Musaab Al-Okaidi