Riccardo
Riccardo

Reputation: 2226

Powershell command line parameter with single quote will break command line

I am invoking a powershell script from a batch file

powershell createshortcut.ps1 "%~n0"

However if the parameter has a single quote (expanded sample)

powershell createshortcut.ps1 "Divertirsi con l'ortografia"

the parser will throw an error

The string is missing the terminator: '.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : TerminatorExpectedAtEndOfString

Obviously the parameter's content is unknown.

Powershell version:

Major  Minor  Build  Revision
-----  -----  -----  --------
5      1      14393  2189

Upvotes: 0

Views: 308

Answers (2)

lit
lit

Reputation: 16266

Tell PowerShell that it will be processing a -File rather than a -Command.

powershell -NoProfile -File createshortcut.ps1 "Divertirsi con l'ortografia"

Upvotes: 2

Akaizoku
Akaizoku

Reputation: 472

Either escape it using a single backtick (`):

powershell createshortcut.ps1 "Divertirsi con l`'ortografia"

Or replace double-quotes by simple ones and use '':

powershell createshortcut.ps1 'Divertirsi con l''ortografia'

Upvotes: 0

Related Questions