diff --git a/src/System.Management.Automation/engine/remoting/commands/StartJob.cs b/src/System.Management.Automation/engine/remoting/commands/StartJob.cs index ff7b844d7f..1436626e00 100644 --- a/src/System.Management.Automation/engine/remoting/commands/StartJob.cs +++ b/src/System.Management.Automation/engine/remoting/commands/StartJob.cs @@ -601,7 +601,7 @@ namespace Microsoft.PowerShell.Commands ThrowTerminatingError(errorRecord); } - if (WorkingDirectory != null && !Directory.Exists(WorkingDirectory)) + if (WorkingDirectory != null && !InvokeProvider.Item.IsContainer(WorkingDirectory)) { string message = StringUtil.Format(RemotingErrorIdStrings.StartJobWorkingDirectoryNotFound, WorkingDirectory); var errorRecord = new ErrorRecord( diff --git a/test/powershell/engine/Job/Jobs.Tests.ps1 b/test/powershell/engine/Job/Jobs.Tests.ps1 index 61765b3f9b..2e8b7aa764 100644 --- a/test/powershell/engine/Job/Jobs.Tests.ps1 +++ b/test/powershell/engine/Job/Jobs.Tests.ps1 @@ -30,8 +30,8 @@ Describe 'Basic Job Tests' -Tags 'Feature' { BeforeAll { $invalidPathTestCases = @( @{ path = "This is an invalid path"; case = "invalid path"; errorId = "DirectoryNotFoundException,Microsoft.PowerShell.Commands.StartJobCommand"} - @{ path = ""; case = "empty string"; errorId = "ParameterArgumentValidationError,Microsoft.PowerShell.Commands.StartJobCommand"} - @{ path = " "; case = "whitespace string (single space)"; errorId = "ParameterArgumentValidationError,Microsoft.PowerShell.Commands.StartJobCommand"} + ##@{ path = ""; case = "empty string"; errorId = "ParameterArgumentValidationError,Microsoft.PowerShell.Commands.StartJobCommand"} + ##@{ path = " "; case = "whitespace string (single space)"; errorId = "ParameterArgumentValidationError,Microsoft.PowerShell.Commands.StartJobCommand"} ) } @@ -86,6 +86,17 @@ Describe 'Basic Job Tests' -Tags 'Feature' { $jobOutput | Should -BeExactly $path.ToString() } + It 'Can specify the working directory with a PSPath' { + try { + Push-Location 'Temp:\' + $job = Start-Job -ScriptBlock { $PWD } -WorkingDirectory $pwd.Path | Wait-Job + $jobOutput = Receive-Job $job + $jobOutput | Should -BeExactly $pwd.Path + } finally { + Pop-Location + } + } + 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" @@ -100,9 +111,9 @@ Describe 'Basic Job Tests' -Tags 'Feature' { } It 'Throws an error when the working directory parameter is ' -TestCases $invalidPathTestCases { - param($path, $case, $expectedErrorId) + param($path, $case, $errorId) - {Start-Job -ScriptBlock { 1 + 1 } -WorkingDirectory $path} | Should -Throw -ErrorId $expectedErrorId + {Start-Job -ScriptBlock { 1 + 1 } -WorkingDirectory $path} | Should -Throw -ErrorId $errorId } It 'Verifies that the current working directory is preserved' {