Powershell opening file path with whitespaces Powershell opening file path with whitespaces powershell powershell

Powershell opening file path with whitespaces


try this:

 start-process -FilePath powershell.exe -ArgumentList "-file `"$filepath`""

edit after comments:

start-process -FilePath powershell.exe -ArgumentList "-file `"$($filepath.path)`""

side note:

$filepath is a [pathinfo] type and not a [string] type.


You can add escaped double quotes so that you pass a quoted argument:

 "`"$filepath`""


I am answering here for a general scenario.

If you need to navigate to a folder for example C:\Program Files from the Powerhsell, the following command won't work as it has white space in between the path.

cd C:\Program Files

Instead embed the path with double quotes as like the below.

cd "C:\Program Files"