Deadly-Bagel almost had it I think. Don't use double quotes in $outputpath to keep Get-Content happy, but add them in your argument list string.

Be sure to escape with backtick `. In fact you might just want to do that with all the paths:

$outputpath = 'C:\Users\bob\Desktop\output new.xml'
Start -FilePath $sqlpackage -ArgumentList "/action:DeployReport /SourceFile:`"$dacpacpath`" /Profile:`"$profilepath`" /OutputPath:`"$outputpath`"" -NoNewWindow -Wait

[xml]$xmldocument = Get-Content -Path $outputpath
Answer from Josh Petitt on Stack Overflow
🌐
Reddit
reddit.com › r/powershell › how to escape spaces in powershell while using double quotes ?
r/PowerShell on Reddit: How to escape spaces in powershell while using double quotes ?
August 12, 2023 -

i am trying to execute a command in powershell wherein it contains spaces in the file path. After looking around, i found out that i need to escape the spaces using ` symbol and use single quotes to handle spaces properly. The issue is that my command contains variables as well so i need to use double quotes to get them to expand while getting executed. is there any way out ? Including example below wherein it only considers the path until the space character

Start-Process -FilePath "cmd.exe" -ArgumentList "/c C:\Users\$env:username\Downloads\Installer\_Silent` Install.cmd" -NoNewWindow -Wait

'C:\Users\Admin\Downloads\Installer\_Silent' is not recognized as an internal or external command, operable program or batch file.

Top answer
1 of 4
18
How come you think that launching powershell that launches cmd that launched bat file is a good idea? Your issue has nothing to do with powershell - this is how cmd.exe, that you launch, looks at parameters - to be specific - /c key looks for a string between space right after /c and whatever next space, which happens to be part of your path. Proper solution - get rid of cmd /c, open install.cmd and adapt whatever is in there to powershell. Highly likely it just launches msi/exe file with a few parameters and lots of spaghetti crap to make it all work in bat (which is unneccessary in powershell) If you still insist on using this wonky stuff, you can utilize string concatenation, something like that: -ArgumentList $('/c "C:\Users\' + $env:username + '\Downloads\Installer\Silent Install.cmd"') Or, you know, just rename this install.cmd file to not have a space in it's name. Why it's even there?
2 of 4
14
The problem here is the lack of quotation marks around your -ArgumentList file path. As you're passing the path via an argument to cmd.exe, it must be properly formatted for cmd.exe (not PowerShell) to interpret. This means file paths with spaces must be wrapped with double quotation marks. # To fix your command, as-is: Start-Process -FilePath cmd.exe -ArgumentList "/c `"$Env:USERPROFILE\Downloads\Installer\_Silent Install.cmd`"" -NoNewWindow -Wait # Or... Start-Process -FilePath cmd.exe -ArgumentList ('/c "{0}"' -f "$Env:USERPROFILE\Downloads\Installer\_Silent Install.cmd") -NoNewWindow -Wait # Assuming the default cmdfile association is in place, explicitly launching cmd.exe is unnecessary. Start-Process -FilePath $Env:USERPROFILE\Downloads\Installer\_Silent Install.cmd -NoNewWindow -Wait # Rather than use Start-Process, run the batch file natively. # This is done synchronously in the same window, so PowerShell will invariably wait for completion. & "$Env:USERPROFILE\Downloads\Installer\_Silent Install.cmd"
Discussions

How to deal with space in the path
In case you want to run powershell.exe -File from the command line, you always have to set paths with spaces in double quotes (""). Also try using the Grave Accent Character () PowerShell uses the grave accent () character as its escape character. Just add it before each space in the file name. More on learn.microsoft.com
🌐 learn.microsoft.com
1
1
April 7, 2022
windows - How to escape spaces in a PowerShell one-liner - Stack Overflow
I want to run an exe with params using powershell one line, like this - powershell -ExecutionPolicy Unrestricted "Start-Process -Path program.exe -ArgumentList somefile.txt, Run" And it works, bu... More on stackoverflow.com
🌐 stackoverflow.com
July 30, 2018
Terminal doesn't handle PowerShell's space escape character correctly
PowerShell supports back tick (`) as a space escape character. Using this when creating a terminal command for PowerShell makes the terminal fail. For example dir folder with spaces The command tha... More on github.com
🌐 github.com
9
August 31, 2017
escaping - How can I escape space in PowerShell? - Stack Overflow
I run this command in PowerShell Start-Process -FilePath 'C:\Program Files\Typora\Typora.exe' -ArgumentList 'C:\Users\Administrator\Desktop\Hello world.md' But Typora says C:\User\Administrator\w... More on stackoverflow.com
🌐 stackoverflow.com
🌐
SS64
ss64.com › ps › syntax-esc.html
PowerShell Escape characters
The standard delimiter for PowerShell is the space character, in addition the split operator and import-csv both accept options for splitting strings with a choice of delimiter. “Be not angry that you cannot make others as you wish them to be, since you cannot make yourself as you wish to be” ~ Thomas A Kempis · Escaping ...
🌐
Qrow Technology Blog
qrow.technology › posts › 2021 › 01 › 04 › Powershell-Space-Escape
Powershell - Escape spaces for scripts | Qrow Technology Blog
January 4, 2021 - For powershell scripting, the method is utilizing the little backtick character (`) on the same key as the tilde (~), below the escape key commonly. Place this backtick just before the space and powershell will detect the space as a space.
🌐
Microsoft Learn
learn.microsoft.com › en-us › powershell › module › microsoft.powershell.core › about › about_special_characters
about_Special_Characters - PowerShell | Microsoft Learn
January 16, 2025 - Then, at the new position, writes a space followed by the word out. ... This special character was added in PowerShell 6.0. The escape (`e) character is most commonly used to specify a virtual terminal sequence (ANSI escape sequence) that modifies the color of text and other text attributes such as bolding and underlining.
🌐
EDUCBA
educba.com › home › data science › data science tutorials › powershell tutorial › powershell escape character
PowerShell Escape Character | List of Escape Sequence in PowerShell
October 11, 2024 - This escape sequence is used to move the position of cursor one position back but characters are not deleted. ... Write-Host "Example of back space escape sequene" $input= "Vignesh Krishnakumar" Write-Host "Actual word is "$input Write-Host "after using back space" Write-Host "vignesh`b`b`bkrishnakumar"
Address: Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
Find elsewhere
🌐
Rlmueller
rlmueller.net › PowerShellEscape.htm
Escaping in PowerShell
May 13, 2026 - If the string is quoted with single ... character is also taken literally and does not need to be escaped. The PowerShell escape character is the backtick "`" character....
🌐
How-To Geek
howtogeek.com › home › windows › how to escape spaces in file paths on the windows command line
How to Escape Spaces in File Paths on the Windows Command Line
September 18, 2023 - You'll have to use the caret character in Command Prompt. If you're familiar with UNIX-like operating systems like Linux and macOS, you might be used to using the backslash ( \ ) character before a space to escape it.
🌐
Techotopia
techotopia.com › index.php › Windows_PowerShell_1.0_String_Quoting_and_Escape_Sequences
Windows PowerShell 1.0 String Quoting and Escape Sequences - Techotopia
To understand the escape character, consider the first example in this chapter, whereby PowerShell interpreted the second word after the -inputobject paramater as an additional argument: PS C:\Users\Administrator> write-output -inputobject hello everyone Write-Output : A parameter cannot be found that matches parameter name 'everyone'. At line:1 char:13 + write-output <<<< -inputobject hello everyone · The reason this occurred was because the space character was interpreted not as a space, but as the delimiter between command line tokens.
🌐
Naga Learnings
pnagarjuna.wordpress.com › 2017 › 09 › 01 › escape-space-in-folder-path-in-powershell-scripts
Escape space in folder path in Powershell scripts – Naga Learnings
September 1, 2017 - Issue:child script path in .ps1 ... with errors as PS will recognize this path till first space. Fix: ` character is the escape character for spaces in PS....
🌐
PowerShell Test-Path
powershellfaqs.com › escape-special-characters-in-variables-in-powershell
PowerShell Escape Character: Backtick and Special Characters
September 9, 2024 - On line 2 below there’s one invisible space after it, so the backtick escapes the space and the next line runs as a separate command: try { Write-Output -InputObject 'first' ` -NoEnumerate } catch { "Failed. PowerShell ran '$($_.TargetObject)' as a separate command."
🌐
GitHub
github.com › microsoft › vscode › issues › 33584
Terminal doesn't handle PowerShell's space escape character correctly · Issue #33584 · microsoft/vscode
August 31, 2017 - PowerShell supports back tick (`) as a space escape character. Using this when creating a terminal command for PowerShell makes the terminal fail. For example dir folder with spaces The command tha...
Author: microsoft
🌐
Stack Overflow
stackoverflow.com › questions › 69098318 › how-can-i-escape-space-in-powershell
escaping - How can I escape space in PowerShell? - Stack Overflow
I want to escape the space, but the single-quoted part is not working... ... You may try inner double quotes inside the single quotes -ArgumentList '"C:\Users\Administrator\Desktop\Hello world.md"' ... There must be a canonical question somewhere. Where is it? ... PowerShell may not quote strings properly when calling external executables.
🌐
SharePoint Diary
sharepointdiary.com › sharepoint diary › powershell › powershell escape characters: all you need to know!
PowerShell Escape Characters: All You Need to Know! - SharePoint Diary
October 17, 2025 - Use escape characters to represent non-printable or reserved characters within strings. These characters are essential for handling special situations and ensuring your PowerShell scripts work as expected.
🌐
PSAppDeployToolkit Community
discourse.psappdeploytoolkit.com › the toolkit › general discussion
Help - Escaping spaces in filepaths - General Discussion - PSAppDeployToolkit Community
December 11, 2021 - Hi everyone, I have been using PSADT for many years now. It’s been such a great tool1 aI now need to package an application called Cubase but I am having issues where the Steinberg application manager errors out which I think is to do with escaping characters.
🌐
PRTG
paessler.com › manuals › prtg › escape_special_characters_and_whitespaces_in_parameters
Escape Special Characters and Whitespaces in Parameters | PRTG Manual
You must escape special characters in parameters that you pass to an executable or script and surround them with quotation marks to make sure that the characters are correctly interpreted. PowerShell scripts in particular require adequate escaping so that the parameters are passed in a valid PowerShell syntax.