Link to home
Start Free TrialLog in
Avatar of enthuguy
enthuguyFlag for Australia

asked on

how to pass argument with surrounded by single quotation to powershell

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
ASKER CERTIFIED SOLUTION
Avatar of enthuguy
enthuguy
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You need to use the escape character for single quote.
Oh... you beat me. :)

Cheers.
Avatar of enthuguy

ASKER

Thanks anyway Pawan, much appreciated