Geeks With Blogs

Fringe SharePoint Continued

I have been working with power shell quite a bit lately, I thought I’d write about 3 tips that have helped me. Notice how it is titled, "Helpful"? not "Ground breaking". It includes helpful commands that I have been using and a nice little Script editor that has one feature enough to win me over. Other's have writen about the commands (most of the time I write so I remember what I've done and how I have resolved issues) but I have not seen others write about other script editors. 

If you have been working with Powershell and you are a Pro at it, this might not be as helpful to you. But as a SharePoint Developer, working with powershell is a newer concept to the average SharePoint Developer or administrator. Very Few SharePoint Administrators and developers used PowerShell for MOSS 2007. It was used it just wasn’t common. What you are used to is StsAdm.exe, and even then you probably used a GUI interface for StsAdm.exe. Well, get used to PowerShell, it can be quite powerful!

Tip #1:

I found myself asking, what is the command for this? And what are the parameters and switches for this command. So here are 2 “Go To” commands I always use.

Get-Command –noun SPSite

This command will get you all the PowerShell commands that have “SPSite” in it.

You will get something like this:

CommandType     Name

Cmdlet          Backup-SPSite

Cmdlet          Get-SPSite  

Cmdlet          Move-SPSite  

Cmdlet          New-SPSite

Cmdlet          Remove-SPSite

Cmdlet          Restore-SPSite

Cmdlet          Set-SPSite

 

Sometimes you want to get examples of all the parameters and switches. Use this command:

Get-Help SPSite

Also use this to get actual examples:

>  Get-Help SPSite –examples

The first command gives you information about the command, the second one actually gives you examples so you can see what the syntax looks like.

 

Tip #2:

Another tip is you can run all STSADM commands off the SharePoint 2010 PowerShell Console. So you can run both type of commands on the same console window. A co-worker of mine was surprised when I was mixing commands, I thought it was common knowledge you could do that.

Tip #3:

The last and more important tip is using A Script Editor. This is pretty common now to write scripts instead of just running the odd command. I always wondered why you would want to write scripts or where it would be applicable. I have a blog post coming, that outlines a very simple example where I did this.

The Windows PowerShell ISE is a Windows Server 2008 Feature. So in order to use it you will need the feature turned on. What you get is a script editor, an input and an output window. I highly recommend you using the a Script editor even for writing plain commands. You will most likely be finding yourself re-using commands or tweaking commands that it’s nice to have a script editor.

I don’t have a screen shot of this because my tip is not on using Windows PowerShell ISE but on explorer other script editor. The one I am using now is PowerGUI. In all reality, it’s just a script editor and it’s not specific to SharePoint and it doesn’t need to be. Experiment with a script editor you like and go with it!

All Script editors are about the same, but this one won me over for one very simple reason. Ever found yourself writing a PowerShell script and trying to press “TAB” to auto finish your command for you? Remember how handy that is? If you are a Developer and send quite a bit of time on Visual Studio you like the “Space” option and auto finish capabilities. The problem is that PowerShell cycles through the commands as you hit “Tab”  and if the command that auto finishes is not the one you like,  you keep pressing “Tab” till you find it. Well, this gets incredibly annoying after a while. It would be nice to have Intellisense, just like in Visual Studio right?

So PowerGUI has it!! You will still have to load the SharePoint Script to load the SharePoint Cmdlets but after that you will have full intellisense and also a description of the command with all the switches. This alone won me over.

Happy PowerShelling! :) 

 

Posted on Friday, July 29, 2011 3:54 PM SharePoint , Development | Back to top


Comments on this post: 3 Helpful PowerShell Tips

# re: 3 Helpful PowerShell Tips
Requesting Gravatar...
The problem is that PowerShell cycles through the commands as you hit “Tab” and if the command that auto finishes is not the one you like, you keep pressing “Tab” till you find it. Well, this gets incredibly annoying after a while.
Left by corset on Jul 30, 2011 3:28 AM

Your comment:
 (will show your gravatar)


Copyright © juanlarios | Powered by: GeeksWithBlogs.net