views:

3035

answers:

13

Windows PowerShell came out last year and got great reviews from many .net bloggers (Hanselman comes to mind). It seemed to be touted as a great new utility that somehow made everything that you would ever do on the command line easier, and integrated with .Net. However, the more I read about it, the more it seems to be a tool that is great for IT professionals, and not much use for developers.

Do you use PowerShell in your dev work? If so, how? Is it worth learning?

Note: After seeing the responses so far, I think it is valid to conclude that PowerShell can be very useful to a .Net developer. However, there is no one answer below that I can label as the answer (so please forgive me for not doing so). I am voting up each answer that I have found helpful. Thanks for the responses!

A: 

Although I haven't learned how to fully use it yet, I'm a fan because it supports most (if not all) of the Unix commands I'm familiar with for navigating using a command line. If you have *nix experience and are developing on Windows, I would recommend using it for that simply because you'll only have to remember one set of commands.

Take what I say with a grain of salt, however. When it comes to building and compiling, I use the command line functionality.

Thomas Owens
+1  A: 

I use it very little for actual dev work. I've used it to setup virtual directories automatically and execute a scipt that sets up IIS with the same settings on all our dev machines

lomaxx
A: 

I use it for IT Pro type stuff a fair bit (for which it's brilliant), but don't think I've used it much for development - occasionally for quickly trying out something like a String.Format. Something I will be doing is to develop powershell commandlets for some of our applications - to allow administrators to perform tasks like user management through powershell, but I don't think this is really what you mean.

Whisk
+2  A: 

It's never come in use as part of my development role, but every now and then I get a task that I'd write a small program to automate, which I now force myself to do in powershell and it takes less time.

For example, I recently moved hundredsthousands of files from one server to another using xcopy and forgot to set the attribute to preserve the creation dates on the files. Powershell to the rescue. Within ten minutes I had a script written and tested that copied the creation dates over without having to re-copy the files.

littlecharva
+1  A: 

Personally, I'm using Python for automating tasks, using WMI if needed. I think that this combination covers most of my needs.

I tested PowerShell, it looks fine to me, but it doesn't worth learning a whole new tool. Besides that, there are excellent resources online to master PowerShell if you need or wants to (PowerShell Live), or even recipes to accomplish tasks without having to pass the whole learning curve for yourself.

PabloG
+6  A: 

It's definitely worth learning. Do you ever convert text? Do you ever manipulate XML? Do you ever automate anything? Simple example. Someone gives you a comma delimited file and you need to pull some fields out of it to import into some other tool/database or to create some list for your program.

If the csv has the field names in the first line of the file, you can do the following in Powershell:

$Data = import-csv "something.csv"

You can then refer to your data using the field names. If you had a field called SSN then you could say $Data[n].SSN. You could also just pipe the import-csv command to something that processed the data including exporting it as XML/html or anything you want with just a few commands. Powershell is full of stuff like this.

It's a tool that gives you tremendous access to a ton of stuff on your workstation and servers, including the complete .NET library. It's a tool that isn't targeted at a type of person. Maybe it's just that the Admin types have been quick to realize how useful it is. I use it every day.

To actually answer the question asked, I use it to automate things I do everyday. I am trying to make it my single scripting language, replacing the things I did in perl, python, vbscript, .bat/.cmd, and one off little utility/conversion programs that I would create.

bruceatk
+4  A: 

I just recently finished version 1 of a project that hosted a PowerShell runtime to execute tasks on remote systems. I disagree wholeheartedly that PowerShell is not a dev's tool.

As a .NET based product, it is a direct analogue to .NET programming. Whole .NET programs can be prototyped in PS, as well as little oneliners to test functionality of methods...etc. That the language architects for PS specifically designed PS's syntax to be close to C#, means there is very little context switch when writing PS scripts and C# code(something I had to do alot recently). You're building on your knowledge already hard won with .NET languages, using PS.

As an automation tool, it is superb. It access's WMI, ADO, ADSI, .NET, COM natively, plus can be spot-welded to work with anything else. This alone makes any Windows automation easier and more powerful. The amount of access to the system is paralled by some other langauges (VBscript, Python) but the ease of use of the language and the benefit of the .NET framework means that some PS scripting is tying together existing code (code reuse) instead of wasting your time writing yet another file zipping routine (for example...)

There are already projects out there that are making build tools (psake comes to mind) to make dev's life easier. Projects like Powershell Community Extensions show the powerful extension capabilities normal every-day devs can achieve. I agree with some of the posters above, I consider anything done to setup build envrionments or work with data for dev tasks, can be done with PS, if not faster/easier/better, but just as well.

James

James Pogran
A: 

It seems to me that WPS is a way to make your life easier to do the things you need. I don't think your going to find WPS integrated into say FireFox or Quicken but those teams may use it to do those things....in short "WPS doesn't make your program, WPS makes making your program easier." ;o)

Keng
+9  A: 

I'm an admin by trade and just starting in the "Dev" world, but I see that PowerShell can be very useful to developers in a number of ways.

  1. Task automation -> Lee Holmes (a developer on the PowerShell team) posted a proof-of-concept called BgShell, which was basically the PowerShell runtime hosted in a windows forms app that listened for keystrokes and kicked off actions written in PowerShell based on them. It also included some clipboard automation.
  2. Quick access to the .NET framework. You don't have to compile and run something or use another program like Snippet Compiler to test some functionality. Load the assembly into your PowerShell session and interact with it. You get all the discoverability of PowerShell (like Get-Member) to explore your object.
  3. Easy to build domain specific languages. James Kovacs wrote a simple build script language with PowerShell called Psake.
  4. It can provide a scripting language for your application. Since PowerShell is part of the 09 Common Engineering Criteria, a lot of Microsoft applications will have interfaces for PowerShell, and familiarity with the language syntax will grow. You can leverage that knowledge by embedding the PowerShell runtime in your application and providing a scripting interface to your users, choosing what objects they will have access to.
  5. Along the same line, if you need to create a command-line interface for your application, PowerShell provides a large part of the underlying plumbing needed for parsing arguments, and other basic tasks, leaving only the business logic for you to write, and providing a consistent interface with other applications (for example, if you have user accounts that need to be managed (that don't already integrate with Active Directory, an admin could (using the Quest AD Cmdlets and your applications interface) Get-QADUser | New-MyApplicationUser and be done. The Exchange 2007 team did this very well. All the functionality is based on PowerShell cmdlets, the GUI calls the cmdlets and shows the user what is being run, so they can build scripts based off of that.
  6. It's just cool! In about 250 lines (including comments), Rob Foust and Jeff Hicks wrote a network sniffer in PowerShell. Easier to use than WinDump for lightweight troubleshooting.
  7. Community - There is a great community focused around PowerShell, including developers. Find out more at PowerShellCommunity.org.
Steven Murawski
A: 

So, I have a follow up question. I have just begun to learn CygWin, and was wondering which of these two programs you experienced guys would recommend learning? I only have very basic needs at the moment, but I may require more power down the road.

Ed Swangren
+1  A: 

@EdSwangren - If you have to work primarily on a Windows platform and work in the .NET space, I would whole-heartedly recommend putting the time in to learn PowerShell. It can leverage your existing .NET experience and code, works with COM, WMI, and ADSI. It allows you access to just about everything on the Windows platform (and that's just V1). V2 is under active development (CTP2 is available now) and will include more remoting, STA threading, and many other improvements.

Many vendors are also supporting PowerShell - from /n Software providing networking cmdlets, to Citrix and VMWare providing management api's via PowerShell.

Steven Murawski
+3  A: 

You can hate Powershell, and yet it can still be incredibly useful to you. I use it for small but important one-liner types of things or in very minor scripts. It really can't compare to C# so as soon as there is any complexity or significant potential reuse at all I switch to C#. Also, importantly, Powershell is so funky that I WANT to recreate solutions from scratch every time, otherwise I forget the quirks, of which there are many. I have heard other people say this too!

Examples of what it's really good for:

  1. Ad hoc text processing. Occasionally people hand me a large data or SQL file, and they want it manipulated into a different form, sometimes in really complicated ways. This alone has saved me incredible amounts of time. It often involves lots of adhoc one-liners and intermediate files. Now that people know I can do this, they tend to hand such projects off to me. Or in some cases they are so wowed that they learn Powershell for themselves.

  2. When I'm at a customer site and desperately need to automate something, and it's the only tool I can and/or am allowed to get my hands on.

  3. Little scripts to log into web sites and navigate to whatever page I'm interested in or working on. I never manually log into a web site that I'm developing anymore. Trivial, but that's one less annoying repeating brain dead task I need to worry about.

  4. One-liners to copy files and projects around and search and replace.

  5. Little scripts to do builds, if there are any unusual complications involved.

  6. Etc. You are bound to have little quirks in your system, where you need to stop/start a service to fix something else, or whatever.

Mike
A: 

I use it to automate as much things as I can. One example is Web UI Automation, to ease application development/testing.

i also use it to generate random input files for various programs. For example, one application is expecting an XML file, and I have a script to build that file with random values and a unique id based on the current time.

I don't use it heavily, but I use it every day.

Philippe