Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In Windows' native CMD processor, you can use & to string commands together so that one runs immediately after the other. A && will run the second command only if the first completes without error.

This is different from piping commands together with | in that output from the first command is not sent to the second command, the commands are just simply run one after the other and output for each is sent to its usual place.

However, I get an error when I try to use & or && in PowerShell. Are there similar functions available in PowerShell, or is this feature being deprecated?

share|improve this question
An interesting question is if powershell's metaprogramming could be used to provide this functionality using && – soandos Aug 20 '12 at 21:08
up vote 13 down vote accepted

The & operator in PowerShell is just the ; or Semicolon.

The && operator in PowerShell has to be run as an if statement.

Command ; if($?) {Command}

share|improve this answer

Try this function, which can be used roughly the same way:

function aa() {
    if($?) {
        $command = [string]::join(' ', $args[1..99])
        & $args[0] $command

Now && can be replaced with ; aa, which while still not perfect is a lot more succinct.

cls && build


cls; aa build
share|improve this answer
Any non-stylistic reason why you're using args[0] and not function aa ($cmd)? – ruffin Nov 25 '14 at 15:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .