Important: take note of PowerShell is open sourced and is available on Linux | Blog | Microsoft Azure which is exciting news! This means we will soon be able to use PowerShell on Windows, Linux and Mac. Although we can use Bash on all three platforms too!
Possibly the best place to start from when new to PowerShell is Scripting with Windows PowerShell on Microsoft's website, which is a great launchpad for getting an introduction to PowerShell as well as digging deeper. There is some background information on PowerShell at Windows PowerShell - Wikipedia, the free encyclopedia which I have also found helpful.
If you want to know which version of PowerShell you are running then open an interactive PowerShell and type
$PSVersionTable you can see from the list "PSVersion" which tells you which version you have and also "PSCompatibleVersions" which tells you which versions of PowerShell you have compatibility with.
I have however noted that whilst my Windows 7 laptop and Windows Server 2012 R2 VM have the same PowerShell versions and "compatible versions" the available cmdlets are different. For example a lot of useful networking and IP related cmdlets like Get-NetIPAddress are only in Windows 8 or Server 2012 and above.
Should you happen to need PowerShell 2.0 for Windows XP then use the following link: Download Update for Windows XP (KB968930) from Official Microsoft Download Center, however I strongly recommend you stop using Windows XP as it stopped getting security updates in April 2014 and so is not safe to use. However there are variants of Windows XP in the embedded and retail space which are still being supported but not for long.
If you need to update PowerShell, so for example, you need PowerShell 4.0 on Windows Server 2008 R2 then How to Install Windows PowerShell 4.0 - TechNet Articles is a very useful article.
These cmdlets are ones I have used and found helpful, clearly there are many more:
Building on this, it is worth noting that when using Start-Process in a script called from IBM's Tivoli Workload Scheduler (TWS) I had to use
-NoNewWindow and then get the output file back in order to show the external process output on the console for TWS to pick up, skipping the redirect command caused some funny issues.
There are a number of these but about_Automatic_Variables is a good place to find out about them.
If there is a CmdLet you want help with then one easy way to get to the Microsoft documentation is as follows:
Get-Help Where-Object -Online
Clearly you can change "Where-Object" for any other Microsoft CmdLet. The "-Online" option basically launches your default web browser.
Sometimes the documentation you want is more along the lines of "What was that command again?", well there is help! You remember it was something to do with items, in which case try
Get-Command *item* and you will get a list of all the CmdLets with the word "item" somewhere in their name, nice!
These things have used and found helpful:
It seems that there are three options, a "read line" approach which requires the enter key to be pressed, a "detect key press" approach and a "message box" technique. None of them are especially hard. The simple "detect key press" is documented at Windows PowerShell Tip: Press Any Key to Continue and the "message box" is explained at Converting VBScript's MsgBox Function . The key press approach does not work from PowerShell ISE and so How to Properly Pause a PowerShell Script gives a more complete solution.
The easy way to parse, search or scan a Windows Event Log is to use the standard Event Viewer, which is either available standalone or via Computer Management. However you can also use PowerShell, which is much more flexible. The obvious cmdlet to use is Get-EventLog, however, whilst being good and flexible has a major issue, in that when working with a remote computer it drags everything local before filtering with Where-Object. So, the preferred cmdlet is Get-WinEvent which is harder to use but the investment is worth it, see Use PowerShell Cmdlet to Filter Event Log for Easy Parsing - Hey, Scripting Guy! Blog - Site Home - TechNet Blogs for more information on this.
My code editing tools of choice are Notepad++ and UltraEdit, and you will find more about them both on this website. However a "hard core" PowerShell scripting friend uses PowerGUI: Simplify your PowerShell and recommends it, so I am passing on his recommendation, because I respect his view, he said:
There are a couple of reasons why I like PowerGUI: You can single step through the script when testing/debugging. It has "Intellisense" style features that will offer the methods, variables and parameter names. Intellisense feature also works with SnapIns and Modules (SharePoint and Azure as an example) and once they have been run, any userdefined functions you have in the scripts.So, well worth looking at!
http://msdn.microsoft.com/en-us/library/system.io.fileinfo.aspx - this documents the information available about files
http://technet.microsoft.com/en-us/library/dd347686.aspx - documentation on Get-ChildItem
PowerShell and Slack – Rambling Cookie Monster - using Slack from PowerShell
This is the starting point for several things PowerShell. The plan is to expand this over time but for now, if you need to get started then http://www.drdobbs.com/windows/powershell-for-developers-with-admin-tas/240150040 is a good place to start.
Also see the Regular Expression page for details for doing grep in PowerShell.
There is a nice script at Script PowerShell: Get Specific Files From Zip Files which is a good example of several things but primarily working with Zip files.
Desired State Configuration or DSC is supposed to be very good, note that Developers perspective on PowerShell Desired State Configuration – IndexOutOfRange is a good summary but is not an introduction or tutorial!