I have a simple PS script that needs to accept a parameter that happens to be a path to a directory. I get this path handed to me and invoke the ps script as follows:
powershell.exe -ExecutionPolicy Bypass -F "C:\temp\ctest\logging test\postinstall.ps1" "C:\temp\ctest\logging test\"
I cannot control the addition of the '\' to the path that is the param to this script, and it must be double-quoted to account for the space in the path. So, what I wind up with is a variable inside my ps script that is the string:
C:\temp\ctest\logging test" <<-- error in path! with the double-quote char. :(
My question is simple, I hope, yet I cannot locate anyone who has solved it, yet. Is there no way to tell powershell not to escape that last double-quote in this scenario?
Thank you for your time, and for educating me.
The issue looks to be only when invoked from CMD. In your script you could do this:
$args[0].TrimEnd('"')
It will remove a trailing double quote if one exists.
Or you could double up the backslash:
C:\>powershell.exe -f C:\echo.ps1 "C:\temp\ctest\logging test\\"
Contents of echo.ps1
Write-Host ('"{0}"' -f $args[0])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With