Chain commands on the PowerShell command line (e.g. POSIX sh &&)

Is there an equivalent in PowerShell of this command construct from sh (and its derivatives):

 $ cmd1 && cmd2 

where cmd2 only starts when cmd1 terminates?

I know that you can combine commands with a semicolon. However, this does not take into account the exit status of the commands.

+11
source share
2 answers

There is no direct analogue of && or ||. However, there are several discussions of alternatives. Here is one example:

conditional execution (& & and ||) in powershell

+2
source

Try the following:

 $errorActionPreference='Stop'; cmd1; cmd2 
+6
source

Source: https://habr.com/ru/post/918489/


All Articles