PowerShell ISE in Server 2008 R2 With SharePoint Modules

16 02 2010

Some of you may have noticed that the ISE environment is not there as a default for Server 2008 R2. This post will go through adding it and also loading the SharePoint modules to enable you to script all your sharepoint bit’s and pieces in a nice environment.

The ISE is just a windows feature. So  click server manager:

Features, Add features:

Tick The Windows Powershell ISE Feature, Click next then install.

It will say that the server may require a restart. The server does not require a restart to add the ISE.

That’s it! It’ll now be on your start menu. If you want to do it all via script then I found this blog from Shay Levy

One thing I found with the ISE was that the Modules and Snapins for SharePoint are not loaded. This means that you can’t run the good old New-SPWeb command! If anyone finds a better way of doing this please let me know but this is how I work so far:

Load PS with modules (As Admin):

Then in the console type “ise” (no quotes) and the ISE will load up – the magic of an Alias!

Run this command from the ISE:

Add-PSSnapin Microsoft.SharePoint.Powershell

And you are good to go with all the SharePoint cmdlets.

Like I said, please let me know if you know a better way of loading the Powershell ISE with all the modules and snapins ready to go!





SharePoint 2010 Powershell Commands Help

14 02 2010

 Yesterday i did a post The first steps to SharePoint 2010 Powershell heaven after which Chris McKinley who is a clever coder added a foot note to the post, so i thought today i would give it a try to see what the output was like and fantastic it all worked and turned out to be a great resource for me so i thought i would share with you the script.

1. Create a folder on your SharePoint 2010 server (I called mine c:\SharePointHelp)

2. Open SharePoint 2010 Management Shell as an Administrator

3. Navigate to the folder you created from within PowerShell

4. Run- foreach($i in Get-Command -module Microsoft.SharePoint.PowerShell) { if($i.CommandType -eq “Cmdlet”){ Get-help $i.Name -full | out-file $i”.txt”}}

 You end up with 549 text files each giving you a breakdown and syntax of all Cmdlets available in SharePoint 2010 powershell.

Thanks Chris and i think i may be changing to loving PowerShell. Dave





The first steps to SharePoint 2010 PowerShell Heaven

13 02 2010

As Chris showed in his post last week Create SharePoint 2010 Sites Using PowerShell PowerShell in SharePoint 2010 is going to be a very useful tool to master over  500 commands as compared to less than 200 with STSADM so I thought I would share with you beginners in the whole PowerShell world a very good starting point on your journey to SharePoint 2010 PowerShell heaven. This simple command will output to a text file a list of all the cmdlets (Command-Lets) available to use with SharePoint 2010. First of all I created a folder on the C drive called PSCmd next start “SharePoint Management Shell” as an Administrator and run the command -

Get-Command  –PSSnapin “Microsoft.SharePoint.PowerShell” | format-table name > C:\PSCmd\SP2010PowershellCommands.txt

OutPut SharePoint 2010 PS Commands

This will output a list of all the available cmdlets to your text file giving you the opportunity to look through them at your leisure.

Output TXT

You can also find a great video on using PowerShell with SharePoint 2010 by Todd Klindt SharePoint MVP here Technet

Dave

Hi Dave, just a quick addition from me.

If you create a new blank folder on the sharepoint server called ‘SharePointHelp’ and then navigate to that with powershell and run this command:

foreach($i in Get-Command -module Microsoft.SharePoint.PowerShell) { if($i.CommandType -eq "Cmdlet"){ Get-help $i.Name -full | out-file $i".txt"}}

You will get a text file for each command containing the full help documentation of each Cmdlet!

Chris.





Create SharePoint 2010 sites using PowerShell reading an XML file

12 02 2010

Just a quick post to show how easy it is to create some sites in SharePoint 2010 using PowerShell by reading an XML file. I’m sure there are some powershell experts out there that can improve the code, but if you need to create a revision gateway during lunch this is the place to start.

Lets start by opening PowerShell with modules on the sharepoint server.

Create a sample xml file:

"<Setup>
 <Sites>
 <TopSiteName>Site1</TopSiteName>
 </Sites>
 <Sites>
 <TopSiteName>Site2</TopSiteName>
 <SubSiteName>Subsite2a</SubSiteName>
 <SubSiteName>Subsite2b</SubSiteName>
 </Sites>
 <Sites>
 <TopSiteName>Site3</TopSiteName>
 <SubSiteName>Subsite3a</SubSiteName>
 <SubSiteName>Subsite3b</SubSiteName>
 <SubSiteName>Subsite3c</SubSiteName>
 </Sites>
</Setup>" | out-file sample.xml

Now we have some data to work with we can create the sites. Three top sites will be created with 2 and 3 subsites below Site2 and Site3. They can be created using:

[xml]$s = get-content sample.xml
foreach ($e in $s.Setup.Sites){
$v = $e.TopSiteName
$b = $e.SubSiteName
new-SPWeb http://sp2010rc/$v -template "STS#0" -addtotopnav -useparenttopnav -name $v
if($b.Length -gt 0) {
foreach ($b in $b){
new-SPWeb http://sp2010rc/$v/$b -template "STS#0" -name $b -AddToQuickLaunch -useparenttopnav
}
}
}

The bit that creates the site is the new-SPWeb command. For information about the command switches run:

get-help new-SPWeb -full

It’s as easy as that! You will now have some SharePoint 2010 sites created in a matter of seconds.

To remove sites you can just use the remove-SPWeb command. This can be scripted in the same way:

[xml]$s = get-content sample.xml
foreach ($e in $s.Setup.Sites){
$v = $e.TopSiteName
$b = $e.SubTopSiteName
if($b.Length -gt 0) {
foreach ($b in $b){
remove-SPWeb http://sp2010rc/$v/$b
}
}
remove-SPWeb http://sp2010rc/$v 

}

The xml file can then be deleted with “Remove-Item sample.xml”

If you really wan’t to get stuck in run “Get-Command -module Microsoft.SharePoint.PowerShell” This will output all the cmdlets that you can use with PowerShell to do great things with SharePoint 2010 combine this with get-help and there is no limit to where you can go!!

So there we have it; One XML file with a site structure creating all the SharePoint 2010 sites in just a few seconds!

Happy site creating. Comments and experiences welcome.





Teaching an old dog new tricks. Using PowerShell to make life better.

8 02 2010

PowerShell has been around for a while now and I use it quite a lot. I’m a programmer so I like to be able to run scripts with loops etc so I get excited that using PowerShell I can display my 8 times tables with this code:

foreach ($num in 1..12 ) { $num * 8}

I also like using the keyboard so am quite happy diving into PowerShell rather than using a GUI. Dave on the other hand is not at all bothered that he can easily solve maths problems, he also often jokes that “it’s called Windows – not typees”. This results in much banter in the office with me often saying that “you could do that in PowerShell” and Dave ignoring me.

I finally thought something had to be done when Dave was installing SharePoint 2010 and FAST search. He had to restart the FAST services. This resulted in a lot of clicking, waiting and more clicking. Time for me to step in with the ever helpful comment of ‘you could do that in Powershell!’.

Dave is not afraid of code views and is often seen firing up a cmd prompt to ping a server or perform an iisreset so I needed to demonstrate how powershell could make his life better and not be something to avoid. I started with ISE.

The Integrated Scripting Environment (ISE) is, in my opinion, is the way powershell should be used. It’s all part of the default PowerShell stuff you get on a normal install of Windows 7 or the like.

With this you get a Notepad style area to write you code (well formatted and colour coded). This also has multiple tabs so you can work on several things at once. There is no point me trying to explain how much easier this is to use than just the powershell window, you need to try it out and see.

The other thing I pointed out to Dave was how easy it was to restart services on a server. So for all thoes SharePoint 2010 FAST services;

Restart-Service -displayname FAST* -whatif

Just like that. The -whatif switch just outputs what will be done, remove the switch and the command will run. So I can run  this code without fear of my browser closing!

From the ISE the commands can be saved, ready for use next time.

Go on, give PowerShell a chance, you’d be barking mad not too.








Follow

Get every new post delivered to your Inbox.