how to pass argument with surrounded by single quotation to powershell

enthuguy
enthuguy used Ask the Experts™
on
Hi
could you help please

How to pass a string value surrounded by single quotation to powershell and use the string inside powershell as it is. Basically, I'm trying to find/replace string in a text file.

From caller batch file
please note. I'm passing 'wf1','wf2','wf3'
powershell -noprofile -executionpolicy bypass -file "E:\\update_listl.ps1 'wf1','wf2,'wf3'"

Open in new window


In Powershell script
$workflow_list=$args[0]
Write-Host $workflow_list
(Get-Content E:\scripts\test.txt) | ForEach-Object { $_ -replace "LIST_OF_WF", $workflow_list } | Set-Content E:\scripts\test2.txt

Open in new window


test.txt content
PROC_NAME in (LIST_OF_WF) few more string XXXXXXXXXXXXXXXXXXX

Open in new window


Current output in test2.txt without single quotation
PROC_NAME in (wf1 wf2 wf3)  few more string XXXXXXXXXXXXXXXXXXX

Open in new window


Expected is
PROC_NAME in ('wf1','wf2','wf3')  few more string XXXXXXXXXXXXXXXXXXX

Open in new window


Thanks in advance
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
Looks like we need to use escape char ` for single quotation and comma.....and it worked fine...thanks anyway

powershell -noprofile -executionpolicy bypass -file "E:\\update_listl.ps1 "`'wf1`'`,`'wf2`'`,`'wf3`'""

Open in new window

Pawan KumarDatabase Expert
Awarded 2016
Top Expert 2016

Commented:
You need to use the escape character for single quote.
Pawan KumarDatabase Expert
Awarded 2016
Top Expert 2016

Commented:
Oh... you beat me. :)

Cheers.

Author

Commented:
Thanks anyway Pawan, much appreciated

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial