man thinking

PowerShell Cribsheet

ProgrammePointers.jpg

I don't know about you, but I find I can never remember that PowerShell command when I need it. Or that reference to the current object - I know it's got a dollar sign and an underscore, or maybe an ampersand. And what about looping? I know it looks like a cross between C# and Unix Shell script, but it takes a lot of syntax errors before I hit on the right combination. The built-in help is good, but sometimes you just need to see an example as a reminder, or that you can edit.

What I need is a handy PowerShell script with just about everything in it that I could need for SharePoint administration, and I suspect you do too. So here it is, to cut out and keep, or rather to download and keep. Just download the text file from the link below and keep it handy (you may need to right-click and select "Save-As" otherwise it could open in a browser window). I'll keep adding to it over time as I come across useful stuff. And if you spot a mistake, please let me know and I will correct it. 

I recommend that you load this file into the Windows PowerShell ISE  (interactive script editor). This gives you a convenient editor to explore the file, and you can edit and highlight the lines you want to run.  You will need to load the SharePoint snap-in using the command asnp Microsoft.SharePoint.PowerShell. That command is included in the cribsheet of course. You can also open it in Notepad if you just want to use it as a reference.

You will notice that the file has a .txt extension and not .ps1. This is so that you can safely use it in the PowerShell ISE. If the file had a .ps1 extension, when you looked in the toolbar you would see a green arrow next to a smaller green arrow on a sheet of paper. The big green arrow runs the whole script, i.e. everything in the file. That would be bad. The other icon runs just the highlighted text (and will be disabled if nothing is highlighted). With the .txt file extension you can still load the file into PowerShell IDE but you don't get a constant invitation to run the whole thing as one gigantic script.

Pair of Scissors Download and keep!