enthuguy
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'
In Powershell script
test.txt content
Current output in test2.txt without single quotation
Expected is
Thanks in advance
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'"
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
test.txt content
PROC_NAME in (LIST_OF_WF) few more string XXXXXXXXXXXXXXXXXXX
Current output in test2.txt without single quotation
PROC_NAME in (wf1 wf2 wf3) few more string XXXXXXXXXXXXXXXXXXX
Expected is
PROC_NAME in ('wf1','wf2','wf3') few more string XXXXXXXXXXXXXXXXXXX
Thanks in advance
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You need to use the escape character for single quote.
Oh... you beat me. :)
Cheers.
Cheers.
ASKER
Thanks anyway Pawan, much appreciated