Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why would I use Powershell over C#?

Tags:

c#

powershell

I know that Powershell is quite powerful in that it is a scripting language in which you have access to the entire .Net framework (thats all I know about it). But i'm struggling to understand what's the big hype about Powershell when I could use C# to code the exact same thing?

like image 362
Draco Avatar asked May 26 '09 07:05

Draco


People also ask

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 C# better than PowerShell?

I might hear someone say (or write) that PowerShell is not as performant than C#, so C# is better. This is… irrelevant, If we are scripting a task to be automated and repeated than performance is likely secondary and writing a nice easy to read and maintain script is what matters.


1 Answers

I think you are asking the wrong question. It should be: "Why should I use C# when I could use Powershell to code the same thing?"

This is the old argument of scripting versus compiled software revisited. A scripting solution is more flexible (you just need Notepad to edit the script, no compiler is required).

For a small task, a script is faster to write, deploy and change than creating a project in Visual Studio, compiling it, deploying it to the target, correcting the code, compiling it again, deploying it again...

For any bigger task, I definitely prefer an IDE that compiles my code. The error messages on a broken build alone are a huge help for finding the cause. (Runtime efficiency is usually better in a compiled software, but with modern CPUs it comes down to a difference of a few milli seconds, so for most projects, it does not matter any more.)

You can do any kind of project in either C# or Powershell. That doesn't mean you should.

like image 52
Treb Avatar answered Oct 10 '22 20:10

Treb