How can I determine what version of PowerShell is installed on a computer, and indeed if it is installed at all?
The variable $Host has a version property that can be used to access the version of PowerShell that is running. Host is a built in PowerShell variable so it's available to you once you start a PowerShell session. If you want to see all the variables avaliable to you type:
PS H:\> Set-Location variable: PS H:\> Get-ChildItem
This will list them all showing the name of the variable and its value.
PS H:\> $Host.Version Major Minor Build Revision ----- ----- ----- -------- 1 0 0 0
PowerShell 2.0(Windows 7)
PS H:\> $Host.Version Major Minor Build Revision ----- ----- ----- -------- 2 0 -1 -1
Calling the version property will return a System.Version object.
As for determining if PowerShell is installed I'm not sure how you wish to do this obviously you can't do this from a PowerShell script, chicken and the egg :-) but if you want to do it manually just click start and run then type 'powershell' if PowerShell has been installed you'll be presented with the PowerShell console.
If you want to programmatically check if PowerShell has been installed check out this post, you could combine it with the other answers on accessing the registry to create a command line application in C# or VB.
I'm debating whether I should learn PowerShell, or just stick with Cygwin/Perl Scripts/Unix Shell scripts, etc.
The benefit of PowerShell would be that the scripts could be more easily used by teammates that don't have cygwin; however, I don't know if I'd really be writing that many general purpose scripts, or if people would even use them.
Unix scripting is so powerful, does PowerShell come close enough to warrant switching over?
EDIT: Here are some of the specific things (or equivalents) I would be looking for in PowerShell:
Tools are just tools.
They help or they don't.
You need help or you don't.
If you know Unix and those tools do what you need them to do on Windows - then you are a happy guy and there is no need to learn PowerShell (unless you want to explore).
My original intent was to include a set of Unix tools in Windows and be done with it (a number of us on the team have deep Unix backgrounds and a healthy dose of respect for that community.) What I found was that this didn't really help much. The reason for that is that awk/grep/sed don't work against COM, WMI, ADSI, the Registry, the cert store, etc, etc. In other words, UNIX is an entire ecosystem self-tuned around text files. As such, text processing tools are effectively management tools. Windows is a completely different ecosystem self-tuned around APIs and Objects. That's why we invented PowerShell.
What I think you'll find is that there will be lots of occasions when text-processing won't get you what you want on Windows. At that point, you'll want to pick up PowerShell. NOTE - it is not an all or nothing deal. Within PowerShell, you can call out to your Unix tools (and use their text process or PowerShell's text processing). Also you can call PowerShell from your Unix tools and get text.
Again - there is no religion here - our focus is on giving you the tools you need to succeed. That is why we are so passionate about feedback. Let us know where we are falling down on the job or where you don't have a tool you need and we'll put it on the list and get to it. In all honesty, we are digging ourselves out of a 30 year hole so it is going to take a while. That said, if you pick up the beta of Windows Server 2008 /R2 and/or the betas of our server products, I think you'll be shocked at how quickly that hole is getting filled.
With regard to usage - we've had > 3.5 million downloads to date. That does not include the people using it in Windows Server 2008 because it is included as an optional component and does not need a download. V2 will ship in all versions of Windows. It will be on-by-default for all editions except Server core where it is an optional component. Shortly after Windows 7/Windows Server 2008 R2 ships, we'll make V2 available on all platforms XP and above. In other words - your investment in learning will be applicable to a very large number of machines/environments.
One last comment. If/when you start to learn PowerShell, I think you'll be pretty happy. Much of the design is heavily influenced by our Unix backgrounds so while we are quite different, you'll pick it up very quickly (after you get over cussing that it isn't Unix :-) ). We know that people have a very limited budget for learning - that is why we are super hard-core about consistency. You are going to learn something and then you'll use it over and over and over again.
Experiment! Enjoy! Engage!
Jeffrey Snover [MSFT] Windows Management Partner Architect
Months later someone turned me on to an awesome solution to this. If you install Git for Windows, it comes with this console app called Git Bash that does exactly what I descibed. I gather that it is derived from MSYS. It's easy and convenient and gives you all the Unix bash command line conveniences. Tab-completion works the way it does in bash (completes up to the point of ambiguity and doesn't try to guess beyond that forcing you to backspace out of an incorrect completion) and you can
control-R to search command history, and history is preserved across restarts.
Can someone recommend a Windows XP program that provides a command line environment? I am an avid Cygwin user, but it doesn't solve my current problem. The problem with Cygwin that's tripping me up is that paths within the Cygwin environment are different from those under Windows, so some things I need to do are failing. My current project requires the Windows environment, not an alternate universe.
I've also considered PowerShell and Windows Services for Unix. I might try them later but for this project, I don't have time to learn a whole programming language that is PowerShell, and I suspect that WSU will have the same path problem as Cywin.
What I'm really looking for to solve my current problem is an app that gives me a Windows console but with some basic amenities added such as...
There is also Console: http://sourceforge.net/projects/console/ it is a replacement for the Windows console window and much more flexible (tabs, transparency, presets, etc) For a better tab completion you need a different command interpreter like 4nt / take command.
As for bash-style completion, recent builds of ConEmu integrate with Clink. More info on what Clink can do here. Or you can use TCC/LE with ConEmu. It also offers powerful bash-style completion plus a whole lot more.