I'm running a PowerShell script invoked from a batch that pass a filename as first parameter. Inside the script I use:
$file = Get-Item -LiteralPath $args[0]
But when the filenames contains a quote (I.E: my'file.txt
) the get-item
triggers an error. I've tried to remove the -LiteralPath
parameter but the problem is the same.
The syntax of the script is
$file = Get-Item -LiteralPath $args[0] write-host $file cmd /c pause
If I run the script against my'file.txt I get:
- C:\m\tag\testscript.ps1 'C:\m\tag\my'file.txt' <<<<
- CategoryInfo : ParserError: (:String) [], ParentContainsErrorRecordException
- FullyQualifiedErrorId : TerminatorExpectedAtEndOfString
Get-Item
is called then you would be gettingFileNotFound
type exception and that is not a fault of PowerShell but maybe the batch that is consuming the character. - Matt