Powershell: Get-Job running when using DIR with '&'

Created on 30 Sep 2019  Â·  4Comments  Â·  Source: PowerShell/PowerShell

Steps to reproduce

   dir & cd ..

Expected behavior

   Show dir output and change directory.

Actual behavior

   Shows Get-Job output and changes directory.

PS C:\programas> dir & cd ..                                                                                                                                                                                                                                                                                                                                                Id     Name            PSJobTypeName   State         HasMoreData     Location             Command
--     ----            -------------   -----         -----------     --------             -------
7      Job7            BackgroundJob   Running       True            localhost            Microsoft.PowerShell.Man…

Environment data

   Name                           Value
----                           -----
PSVersion                      6.2.3
PSEdition                      Core
GitCommitId                    6.2.3
OS                             Microsoft Windows 10.0.18362
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
Issue-Question Resolution-Answered

Most helpful comment

& as a suffix is the Background Job Operator in PowerShell, it uses Start-ThreadJob to kick off a background job in another runspace.

If you want to execute commands in sequence, you can end a statement with ; to execute both:

dir ; cd ..

All 4 comments

& as a suffix is the Background Job Operator in PowerShell, it uses Start-ThreadJob to kick off a background job in another runspace.

If you want to execute commands in sequence, you can end a statement with ; to execute both:

dir ; cd ..

@vexx32
Background Job Operator & creates a background job, not a thread job.

I see, thanks for the infos! I came from batch so didn't know that :D

@Ronkiro you might find PSKoans a useful resource. 🙂

Was this page helpful?
0 / 5 - 0 ratings