When and Why should I prefer to use PowerShell?

by DougFinke at 2012-08-23 06:39:00

I asked John Cook, he reviewed my book, what two questions didn’t I cover.

Here they are:
[list=1]
[]What are the advantages to PowerShell?[/]
[]When should I use PowerShell and when should I use C#?[/][/list]
What do you think?
by willsteele at 2012-08-23 07:00:02
Both good questions. To be fair, I think covering "what are the disadvantages to PowerShell" would help people size up the product in an useful way. I recently saw a piece talking about some of the downsides of PowerShell, many of which Kirk responded to. But, that is an often unexplored area worth mentioning.

In answer the latter question, code (and theory) demonstrating the pros and cons of when to use which and why will be very compelling. Just saying use PS versus C# here, here and here doesn’t convince skeptics (or at my office, developers who use C#). But, if you show, for instance, a simple command you could accomplish in 1 line of PowerShell may take 15 lines of C#, that could weigh well in the favor of the scripting language. Also, I think it’s important to remind people that you can use inline C# with Add-Type and accomplish two goals with one language in some cases so you don’t have to worry about redoing a large code base. Sometimes just porting it directly with the right cmdlet can allow existing code to live on.
by JeffH at 2012-08-23 07:52:12
This is a question that will have different answers depending on whether you are asking IT Pros (ie mainly Windows Admins) or professional developers. Although in both camps there are probably a few items I would take into account:

Who will the the intended user of whatever it is I’m creating and how will they be using it?
Am I re-inventing the wheel?
Are there any sort of dependencies I need to take into account?
by yooakim at 2012-08-23 10:23:29
Killing old habits is always hard! I’ve been working with programming and operations since 1984. Since then many generations of both developers and operators have stalled. They have stalled in the sense that they learnt a trick or two and never changed their habits.

PowerShell is a big-step forward regardless if you come from a programmer/developer or systems administration background. PowerShell is deceptively easy and yet very powerful. It’s also elegant and easy to document. The way PowerShell let’s me tie together the .NET Framework (and more) is really uniqe!

Today I had to get som old datat out of a MySql databas (running in Linux clusters) - this took some 10 lines of PowerShell code (with the MySql.Data class) and then I could export anything my client wanted to CSV, XML or other. Best of all this piece oc code can easily be re-used the next time I need to work with MySql data.

For me this is the killer feature; to be able to quickly do-and-document-what-you-did! When it’s easy to edit/test it encouages me to improve!

I am not necessarily one who like when command lines get’s too convoluted. Old languages such as APL (http://en.wikipedia.org/wiki/APL_(programming_language)) were elegant bout could hardly be understood by anyone except the original author. The convetions in PowerShell are good and they lay a foundation for making cmdlets that others can use.

'nough said.

I like PowerShell!
by DougFinke at 2012-08-26 07:24:04
Good old APL, a write once language. I go back a couple years before that yooakim. :slight_smile:

On the Mainframe I was introduced to scripting with CLIST and REXX.
One of the reasons I was drawn to Monad/PowerShell was it’s inspiration from AS/400 and DEC DCL.

The culture back then, everything was written in IBM ASSEMBLER Language (BAL) . Registers, OPCodes etc.

I found using a scripting language to sketch out ideas got the software in front of clients quicker and helped everyone involved make quicker decisions about the shape of the problem.

Then, we could move forward and keep the pieces that just worked (in script) and bake others into BAL for performance or reuse in larger solutions.

Like others have mentioned. There are several aspects to consider when choosing an approach to building software.

I’m thinking PowerShell raises the possibilities and leans more to an "AND" compared "Either/Or" choice point.

Drawing from the gaming community. Lua is very successful in it’s application in the World of Warcraft.

A scripting glue for the hardened C++ components that make up the game.

We also see this from Microsoft, they are delivering new PowerShell cmdlets over their existing products. In PowerShell v1 we saw this done in Microsoft Exchange, plus a GUI layered on top of PowerShell.

I believe to become more agile developers, we need to be exposed to this and begin to embrace it.