diff --git a/src/System.Management.Automation/engine/hostifaces/PowerShellProcessInstance.cs b/src/System.Management.Automation/engine/hostifaces/PowerShellProcessInstance.cs
index 2ec10fa7705..f0f71454630 100644
--- a/src/System.Management.Automation/engine/hostifaces/PowerShellProcessInstance.cs
+++ b/src/System.Management.Automation/engine/hostifaces/PowerShellProcessInstance.cs
@@ -41,7 +41,7 @@ static PowerShellProcessInstance()
}
///
- /// Initializes a new instance of the class. Initializes the underlying dotnet process class.
+ /// Initializes a new instance of the class. Initializes the underlying dotnet process class.
///
/// Specifies the version of powershell.
/// Specifies a user account credentials.
@@ -56,9 +56,9 @@ public PowerShellProcessInstance(Version powerShellVersion, PSCredential credent
{
processArguments = string.Format(
CultureInfo.InvariantCulture,
- "{0} -wd {1}",
+ "{0} -wd \"{1}\"",
processArguments,
- workingDirectory);
+ workingDirectory.Replace("\"", "\"\""));
}
if (initializationScript != null)
@@ -105,7 +105,7 @@ public PowerShellProcessInstance(Version powerShellVersion, PSCredential credent
}
///
- /// Initializes a new instance of the class. Initializes the underlying dotnet process class.
+ /// Initializes a new instance of the class. Initializes the underlying dotnet process class.
///
///
///
diff --git a/test/powershell/engine/Job/Jobs.Tests.ps1 b/test/powershell/engine/Job/Jobs.Tests.ps1
index 4e0332afdbb..cdccbf6b253 100644
--- a/test/powershell/engine/Job/Jobs.Tests.ps1
+++ b/test/powershell/engine/Job/Jobs.Tests.ps1
@@ -77,10 +77,20 @@ Describe 'Basic Job Tests' -Tags 'CI' {
$ProgressMsg[0].StatusDescription | Should -BeExactly 2
}
- It 'Can use the user specified working directory parameter' {
- $job = Start-Job -ScriptBlock { $pwd } -WorkingDirectory $TestDrive | Wait-Job
+ It 'Can use the user specified working directory parameter with whitespace' {
+ $path = Join-Path -Path $TestDrive -ChildPath "My Dir"
+ $null = New-Item -ItemType Directory -Path "$path"
+ $job = Start-Job -ScriptBlock { $pwd } -WorkingDirectory $path | Wait-Job
$jobOutput = Receive-Job $job
- $jobOutput | Should -BeExactly $TestDrive.ToString()
+ $jobOutput | Should -BeExactly $path.ToString()
+ }
+
+ It 'Can use the user specified working directory parameter with quote' -Skip:($IsWindows) {
+ $path = Join-Path -Path $TestDrive -ChildPath "My ""Dir"
+ $null = New-Item -ItemType Directory -Path "$path"
+ $job = Start-Job -ScriptBlock { $pwd } -WorkingDirectory $path | Wait-Job
+ $jobOutput = Receive-Job $job
+ $jobOutput | Should -BeExactly $path.ToString()
}
It 'Throws an error when the working directory parameter is ' -TestCases $invalidPathTestCases {