14

I'm just getting started in PowerShell and one of my sysadmins told me that Powershell can do as much as C# can for systems management, if not more.

Please forgive the ignorance of this question, but when would I use Powershell over C#?

makerofthings7
  • 60,103
  • 53
  • 215
  • 448

3 Answers3

25

1) PowerShell is good for relatively small well defined tasks, especially ephemeral one-day tasks and interactive tasks when you are coding right in the command line. If a task requires just a few lines of PowerShell code (and you know that because you know PowerShell well enough!) then launching a full C# project is often overkill.

2) C# is much better for large projects or where performance is critical. It is better for any project that will presumably require debugging and troubleshooting.

3) PowerShell and C# can perfectly work together. It is easy to call one from another. PowerShell is good for connecting .NET components. You can implement your complex and performance critical pieces in C# and then combine and glue those pieces together with PowerShell.

Roman Kuzmin
  • 40,627
  • 11
  • 95
  • 117
  • 2
    I disagree on the second part of point 2. PowerShell has a respectable native debugging facility and all of the modern script editors do a good job implementing it. – xcud Nov 16 '10 at 15:37
  • 1
    I know the answer is quite old, but for point 1 it stated that "...then launching a full C# project is often overkill.". If you need a quick (and usually dirty) solution, you could just use [Linqpad](https://www.linqpad.net/) – Enthusiastic Programmer Mar 26 '16 at 20:59
  • 1
    In 2020, I agree with xcud that VS Code is brillant in debugging Powershell. It is a "board tool" coming with Windows 10 out of the box and has a PowerShell Plugin. – Timo Jun 29 '20 at 09:23
19

When I worked in the Windows build lab a LONG time ago (1997) the rule I was taught that if the code satisfies either of these two conditions write it in interpreted script, otherwise write it in compiled code:

  1. there's more overhead than code (using/include lines, function declaration, etc)
  2. there's a better than 10% chance that the code will change before it gets run again
xcud
  • 14,422
  • 3
  • 33
  • 29
1

From an infrastructure point of view, Hyper-V is getting huge in the virtualization market, it's outgrowing VMWare every year in terms of market share growth. Concerning SCVMM automation, if you want to leverage VMM functionality of managing multiple hosts running different hypervisors, VMM powershell interface is the only option.

Klawfinger
  • 29
  • 4