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.

Is it possible run two commands at once such as

cd "C:/users/..." and Dir | -Rename-Item -NewName {...}

I want to know if this is possible since it will drastic speed up what I am trying to do.

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

From your description, it sounds like you are trying to run two commands sequentially. The way to do this is with a script. PowerShell uses .ps1 files for scripts. Running scripts in PowerShell is a little more complicated then scripts through the command line. You will need to enable running scripts, create the script, and finally run the script with the right command.

First you need to enable running scripts. Open PowerShell and run the command:

Set-ExecutionPolicy RemoteSigned

This will allow you to run scripts from your local computer.

Second, you need to write the script, You can use any tool you like, such as notepad, but if you want to get fancy, I recommend, PowerGUI script editor or Notepad++ so you can get proper syntax highlighting and such. In the case of your script, just copy the code onto two lines:

cd "C:/users/..." and 
Dir | -Rename-Item -NewName {...}

Finally you need to run the Script, this can be done in PowerGUI with the F5 key, or you can do it from the command line by browseing the the folder and typing:

.\Scriptname.ps1

The .\ is important, as this is how PowerShell knows that this is a script that it should run.

Powershell scripts can be a bit daunting at first, but you will find that with a bit of practice, you can do almost anything with them.

share|improve this answer
add comment

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.