|
|
Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
Run Powershell script with parameters containing special chars
Hi
I have a Powershell step launching Test.ps1 ,in Input section I have 2 params which are 2 macros %MyParam1% and %MyParam2% (see the attach). The problem is MyParam2 contains special chars [% so the step fails: Error expanding macros or script in property Parameters: Test2]<Error parsing macros at position 8> I tried as well with a batch step and it fails also: Error expanding macros or script in property command: C:\Windows\System32\WindowsPowerShell\v1.0\powersh ell.exe -nologo -noninteractive -executionpolicy Unrestricted "& 'C:\Program Files\VisBuildPro9\Test.ps1' -Param1 'Test1' -Param2 'Test2]<Error parsing macros at position 8>' Is there any way to launch the script Test.ps1 with second param containing special chars? |
#2
|
|||
|
|||
[vbld_EscapeString(vbld_AllMacros()("MyParam2"))]
https://kinook.com/VisBuildPro/Manual/specialchars.htm |
#3
|
|||
|
|||
It works,thanks a lot!
|
#4
|
|||
|
|||
I have one more issue,if param MyParam2 contains { I got an error at step Run Test PowerShell script-with parameters :
3/8/2023 12:26:39 AM: Building project step 2 - Run Test PowerShell script-with parameters... C:\Windows\System32\WindowsPowerShell\v1.0\powersh ell.exe -nologo -noninteractive -executionpolicy Unrestricted "& 'C:\Program Files\VisBuildPro9\Test.ps1' Test1 Test{2[]??" Missing closing '}' in statement block or type definition. + CategoryInfo : ParserError: ( : ) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : MissingEndCurlyBrace This is because the powershell script is launched with parameters without enclosing ' ' For example if I launch the script from a batch file step by adding enclosing ' ' all is ok: 3/8/2023 12:30:42 AM: Building project step 3 - Run PowerShell script from batch step... C:\Windows\System32\WindowsPowerShell\v1.0\powersh ell.exe -nologo -noninteractive -executionpolicy Unrestricted "& 'C:\Program Files\VisBuildPro9\Test.ps1' -Param1 'Test1' -Param2 'Test{2[]??' Param1= Test1 Param2= Test{2[]?? Is there a way to add enclosing ' ' when using a Powershell step? I attached the bld project. |
#5
|
|||
|
|||
Add the single quotes to the parameter value.
|
#6
|
|||
|
|||
Tried that,same error:
C:\Windows\System32\WindowsPowerShell\v1.0\powersh ell.exe -nologo -noninteractive -executionpolicy Unrestricted "& 'C:\Program Files\VisBuildPro9\Test.ps1' Test1 ''Test{2[]??''" Missing closing '}' in statement block or type definition. + CategoryInfo : ParserError: ( [], ParentContainsErrorRecordException + FullyQualifiedErrorId : MissingEndCurlyBrace I see now the second param has 2 chars ' at beginning and 2 at end although I added just one. |
Tags |
powershell , special charcaters |
Thread Tools | |
Display Modes | Rate This Thread |
|
|