tags:

views:

580

answers:

4

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?

+1  A: 
  • It's not a compiled language.
  • It has a plugin ecosystem with lots of 'libraries' for doing various domain specific things like copying files, playing with AD, Exchange.
  • It's the right tool for a different, slightly overlapping set of jobs.
  • It's a lot more powerful and consistent than CMD.EXE and other things evolved from command shells that needed to fit into 8K RAM.

And why are you using C# anyway, ILASM can do everything with much more control, and you're just calling stuff in the BCL anyway.

Ruben Bartelink
+7  A: 

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, deploaing 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.

Treb
+4  A: 

When not using Powershell as a shell but a programming environment, you can think of Powershell as a kind of interactive .NET playground. I'd never use Powershell for GUI prototyping but I have used it in the past for playing around with .NET objects and their methods to solve a particular problem. Simply altering a commandline is more productive than doing an edit/save/compile/run cycle every time you make a change.

Furthermore, the appropriate domains for either language are very different. Powershell is, at its heart an adminstration and automation tool, having streamlined access to many things that may be more awkward to use from another environment, like the Registry, certificate store, WMI and others.

You probably don't want to write an enterprisey database application with Powershell and you probably don't want to write a C# program just to copy some stuff around in the file system.

Joey
+1  A: 

I generalized your question into the following:

Why would I use (higher level language that I know little about) over (lower level language I know more about)?

The point of a higher level language is to abstract common tasks so that they are faster to write. Many people who ask this question cannot conceive of this benefit of a higher level language because they are already comfortable with their lower level language.

In the end, it all comes down to your willingness to learn the abstractions of a higher level language in hopes that you can become as proficient in it as the lower one.

Unknown
I don't think Powershell is inherently "higher-level" than C#, it's just that their respective task domains are very different.
Joey
PowerShell is indeed higher level, if only because the "pipeline" concept makes it easier to reuse and combine "pieces" ... Certainly PowerShell falls down to a lower-level when you need to do something for which there isn't already an existing script or cmdlet, but the composability of cmdlets and functions is much higher level than anything in C# (or Ruby/Python/Perl for that matter).
Jaykul