File tree Expand file tree Collapse file tree
src/System.Management.Automation/engine/remoting/commands
test/powershell/engine/Job Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -484,7 +484,7 @@ public virtual ScriptBlock InitializationScript
484484 /// Gets or sets an initial working directory for the powershell background job.
485485 /// </summary>
486486 [ Parameter ]
487- [ ValidateNotNullOrEmpty ]
487+ [ ValidateNotNullOrWhiteSpace ]
488488 public string WorkingDirectory { get ; set ; }
489489
490490 /// <summary>
@@ -601,7 +601,7 @@ protected override void BeginProcessing()
601601 ThrowTerminatingError ( errorRecord ) ;
602602 }
603603
604- if ( WorkingDirectory != null && ! Directory . Exists ( WorkingDirectory ) )
604+ if ( WorkingDirectory != null && ! InvokeProvider . Item . IsContainer ( WorkingDirectory ) )
605605 {
606606 string message = StringUtil . Format ( RemotingErrorIdStrings . StartJobWorkingDirectoryNotFound , WorkingDirectory ) ;
607607 var errorRecord = new ErrorRecord (
Original file line number Diff line number Diff line change @@ -86,6 +86,17 @@ Describe 'Basic Job Tests' -Tags 'Feature' {
8686 $jobOutput | Should - BeExactly $path.ToString ()
8787 }
8888
89+ It ' Can specify the working directory with a PSPath' {
90+ try {
91+ Push-Location ' Temp:\'
92+ $job = Start-Job - ScriptBlock { $PWD } - WorkingDirectory $pwd.Path | Wait-Job
93+ $jobOutput = Receive-Job $job
94+ $jobOutput | Should - BeExactly $pwd.Path
95+ } finally {
96+ Pop-Location
97+ }
98+ }
99+
89100 It ' Can use the user specified working directory parameter with quote' - Skip:($IsWindows ) {
90101 $path = Join-Path - Path $TestDrive - ChildPath " My "" Dir"
91102 $null = New-Item - ItemType Directory - Path " $path "
@@ -100,9 +111,9 @@ Describe 'Basic Job Tests' -Tags 'Feature' {
100111 }
101112
102113 It ' Throws an error when the working directory parameter is <case>' - TestCases $invalidPathTestCases {
103- param ($path , $case , $expectedErrorId )
114+ param ($path , $case , $errorId )
104115
105- {Start-Job - ScriptBlock { 1 + 1 } - WorkingDirectory $path } | Should - Throw - ErrorId $expectedErrorId
116+ {Start-Job - ScriptBlock { 1 + 1 } - WorkingDirectory $path } | Should - Throw - ErrorId $errorId
106117 }
107118
108119 It ' Verifies that the current working directory is preserved' {
You can’t perform that action at this time.
0 commit comments