If Powershell is built on top of .Net, what is the reason to write scripts instead of C# code? [closed]

StackOverflow https://stackoverflow.com/questions/13692786

Вопрос

As a person who is new to Powershell I am not 100% clear at one point:

If

"In PowerShell, administrative tasks are generally performed by cmdlets (pronounced command-lets), specialized .NET classes implementing a particular operation."

What are the reasons to write scripts instead of writing .Net executables with those classes and compile them as console applications?

Это было полезно?

Решение

You could just as easily ask the question, what are the reasons to write applications in .NET when you can just as easily create fully fledged desktop and server software in PowerShell?

There are reasons to use both in different circumstances. PoSH scripts themselves are simply small text files, and are very easy to write and maintain. As someone who dabbles in both, I'd say in a lot of circumstances system maintenance tasks are much easier to accomplish with a quickly whipped up PoSH script than with a .NET application.

That said there are some things which are much easier to accomplish in .NET (I use C# myself), but the process of developing these is much more cumbersome, and requires an additional skillset not common among SysAdmins.

Put simply, PoSH is targeted at SysAdmins and .NET is targeted at developers, but that's not to say there isn't some room for crossover.

Другие советы

I full agree with @Matt G answer.

I just want to add one thing which is arround culture. Windows SysAdmins culture is more "click" driven (admin by the Graphic User Interface) than programming driven.

I use to work in Unix world, there, SysAdmins where power scripters (sh, csh, ksh ...) and when needed they where able to write a small 'C' program on the corner of the table (for perfomance, or to act as a complex file filter etc).

Since the begining of .NET (2001) Windows SysAdmins can use the C# compiler (available from the .NET directories as CSC.EXE) as Linux or Unix were able to use 'cc' compiler, but they don't. The best ones were using WSH (Window Script Shell), but VBScript was not so easy to use and need to discover different COM objects for each case.

Microsoft, multiply the ways to urge Windows SysAdmins to use command lines and scripting (WSH, netsh, wmic etc.). For a few years now (2006) Microsoft decided to take the Sysadmins by the hand, and gave them a Power tool, removing the power from the user interface (Exchange 2007). So now SysAdmin can't do anything else than use PowerShell. But as they are not devolppers, the language is interpreted and the 'object culture' is somehow hidden for the beginers.

Now good Windows SysAdmins can develop their own C# class and insert them inline into their PowerShell scripts, SysAdmins are not developpers, they just need to automate their process.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top