Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is PowerShell a good upgrade for a batch file?

Tags:

I package our server releases into zip files using a batch file (Windows), running the command-line version of WinZip. Previously we did this sort of thing "by hand" but I developed the process of automating it with a batch file.

The batch file has become quite complicated because our product is complicated (i.e., Which sections are we releasing this time? Are we releasing the config files as well?) and I'm starting to run into some frustrating limitations with batch files.

Would PowerShell be a good thing to investigate as an "upgrade" to the batch file? Or is that complete overkill given that most of what it would be doing is firing off DOS commands?

Bonus: can PowerShell consume .NET assemblies? As in, could I start doing the zipping with SharpZip?

like image 541
Tom Kidd Avatar asked Jan 23 '09 22:01

Tom Kidd


People also ask

Is PowerShell compatible with batch?

PowerShell supports batch files and command-line tools. Moving to PowerShell doesn't mean you have to abandon batch files or command-line tools. Old batch files will still run in PowerShell, and command-line tools still work just fine. PowerShell's script language is a real programming language.

Why is PowerShell better than batch?

As such, PowerShell cmdlets and scripts can do so much more than batch scripts. And perhaps most interesting is that PowerShell lets you pipe the output of one cmdlet as the input to another cmdlet as objects. Most other shells, including Bash, can only pipe information from one command to another as plain text.

Should I use PowerShell instead of cmd?

Cmd is used primarily to execute batch commands, do some primary troubleshooting whereas PowerShell can be used for executing batch commands as well as administrative purposes. Scripts can also be written in PowerShell to automate the tasks. PowerShell also has an ISE which makes it easier to write and debug scripts.

Is batch and PowerShell the same?

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.


2 Answers

If you have a working solution, then you don't need to go to powershell. Having said that, if you plan to make changes or improve the process then I would highly recommend powershell as the way to go. Powershell can access .Net assemblies...mostly. Some assemblies are structured in a way that makes it more difficult than others.

You can check here for some resources if you decide to look at powershell.

like image 197
EBGreen Avatar answered Oct 25 '22 12:10

EBGreen


Initially I was really excited about PowerShell. Finally a powerful native shell on Windows. However, I quickly realized that compared to your favorite unix shell PowerShell is just way too verbose. Even doing simple stuff takes way too much typing compared to what you can do with bash and GNU tools for Win32.

I like the idea, that the shell knows about different types, but if I need to do that much additional work, I prefer just getting the necessary data with the various unix stream editors.

EDIT: I just had another look at PowerShell, and I have to admit, that it does have some really useful features that are not available for the traditional unix style tools.

For one the PowerShell owns all the commands which means that it can provide a much more coherent set of features. Parameters are treated uniformly, you can search for commands, parameters and so forth using wild cards which is really useful.

The second great feature is that PowerShell lets you enumerate sources which are normally not available to stream editors such as the Windows registry, the certificate store and so forth. Of course you can have tools that does this for you and present it as text, but the PowerShell approach is just really elegant IMO.

like image 36
Brian Rasmussen Avatar answered Oct 25 '22 12:10

Brian Rasmussen