I have a PowerShell script that needs a path passed to it as parameter and surrounded with double quotation because path may be contains space. But my problem is when the path is root of drive for example "E:\"
the passed parameter in the script converted to E:" (must be E:\
) how to solve this problem? When I use single quotation the passed strings is 'E:\'
and contains the quotations!
Please help
my code sample:
in test.ps1
Write-Host ($args[0])
Result:
.\test.ps1 "E:\"
E:"
.\test.ps1 'E:\'
'E:\'
.\test.ps1 "'E:\'"
'E:\'
.\test.ps1 "E:\Test"
E:\test
I call the script from registry like this: powershell -File "test.ps1" "%V"
I solved problem by changing "%V"
to '%V'
and in the script I use trim function to removes single quotations
$Arg0 = ($args[0])
$Path = $Arg0.trim("'")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.