I am running a script which has $FileName variable containing the absolute path with spaces. Due to the space within the directory name and file name, the script fails to ex
In addition to the backtick escape character (`), you can use the -f format operator:
`
-f
$FilePath = Join-Path $Dir -ChildPath "$File.txt" $FilePathWithQuotes = '"{0}"' -f $FilePath
This will ensure that $FilePath is expanded before being placed in the string
$FilePath