PM Laforest
PM Laforest

Reputation: 102

Differences between commands run in .bat file and powershell.exe

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?

Upvotes: 0

Views: 16365

Answers (2)

Jeff Zeitlin
Jeff Zeitlin

Reputation: 10764

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.

Upvotes: -2

daddygames
daddygames

Reputation: 1928

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.

Upvotes: 5

Related Questions