1

I wanted to download a scoop installer and I find out that my command is not working in a .bat file but works when I copy/paste it into PowerShell.

Here is the command and a picture to make things perfectly clear:

iex (new-object net.webclient).downloadstring('https://get.scoop.sh')

The output of PowerShell:

Enter image description here

Why is it the case and maybe the things that we need to be aware of when we put commands in .bat file?

6
  • PowerShell is not the same thing as the Windows Command Processor. They share some commands, but PowerShell includes extra features. By default, Windows executes BAT and CMD files using cmd.exe. Commented Jan 11, 2018 at 20:45
  • yes, thanks for the advice, maybe my title is misleading, I really meant powershell.exe. I need to be more precise next time. Sorry it's my first question. Commented Jan 11, 2018 at 20:49
  • You can be more precise this time! You can always edit your question and fix it. Commented Jan 11, 2018 at 20:50
  • @PMLaforest changing to powershell.exe doesn't change the answer, though. a .BAT file will execute, by default, using cmd.exe. You could change the file extension to .ps1, which should then default to using powershell.exe. Otherwise, you have to explicitly run the file against PowerShell. Commented Jan 11, 2018 at 20:52
  • @daddygames thank you for your precise answer, This is what I was looking for ! Great help ! Commented Jan 11, 2018 at 21:05

2 Answers 2

6

PowerShell share some commands with Windows Command Processor (cmd.exe). PowerShell includes extra features and commands that aren't in cmd.exe. Your command appears to be using PowerShell script.

A .BAT file will execute, by default, using cmd.exe. You could change the file extension to .ps1, which should then default to using powershell.exe. Otherwise, you have to explicitly run the file against PowerShell.

Sign up to request clarification or add additional context in comments.

Comments

-2

Batch files are generally executed by CMD.EXE; PowerShell is executed by PowerShell.exe. The two are different, and scripts that work in one will not work in the other. The code that you've pasted into your question is unquestionably PowerShell, not batch. You might find it useful to look at some of Microsoft's PowerShell basics.

1 Comment

PowerShell can run batch files but Command Prompt cannot run ps1 files. The reason that the script runs in the image OP posted is exactly what I said above.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.