Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

In cmd prompt, you can run two commands on one line like so:

ipconfig /release & ipconfig /renew

When I run this command in PowerShell, I get:

Ampersand not allowed. The & operator is reserved for future use

Does PowerShell have an operator that allows me to quickly produce the equivalent of & in cmd prompt? Any method of running two commands in one line will do. I know that I can make a script, but I'm looking for something a little more off the cuff.

share|improve this question
1  
Fun Note: Between Serial ports and Serialisation, this question is virtually impossible to search for. –  David Jun 26 '13 at 17:25
    
To be nerdy... It's very easy to search for it. It's just quite hard to get a relevant set of hits. :) (+1 for great question) –  Konrad Viltersten Jun 27 at 16:01

2 Answers 2

up vote 26 down vote accepted

Use a semicolon to chain commands in powershell:

ipconfig /release; ipconfig /renew
share|improve this answer
    
Will they run in parallel or sequentially? –  Tarkus Jul 16 at 1:13
    
This will run them sequentially, as does the & operator in cmd.exe. –  Squeezy Jul 23 at 5:38

A semi colon will link the commands as the previous answer stated, although there is a key difference to the behaviour with the & operator in Dos.

In Dos, the variable substitution takes place when the line is read. This allows some neat possibilities such as swapping variables without an interim:

set a=1
set b=2
set a=%b% & set b=%a%
echo %a%
echo %b%

Would result in:

2
1

As far as I know, there is no way to replicate this behaviour in Powershell. Some may argue that's a good thing.

Edit: There is in fact a way to do this in Powershell: $b, $a = $a, $b Will result in a single line swapping of the variable values

share|improve this answer
    
$b, $a = $a, $b cool! :) –  Tarkus Jul 16 at 1:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.