C# – Why would I use Powershell over C#


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?

Best Solution

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.