SPModule and Sharepoint 2010; the power of the PowerShell

 

Check out my Google sidewiki post here: http://www.google.com/sidewiki/entry/flowergirldujour/id/Swp7WYEPjDdbMeaYQkPn8Hir4MY

And definitely download this module so that you can use SPModule…

SPModule.zip

Here is what the interface looks like:

From Zach Rosenfield’s blog, who is the Sharepoint Program Manager at Microsoft:

SPModule.HelloWorld()

Welcome to the introduction of SPModule.  SPModule is a Windows PowerShell module written by members of the SharePoint Product Group in our spare time.   SPModule is an example of how we would envision you accomplish various common tasks within Windows PowerShell in a SharePoint 2010 environment.  We hope to position various best practices from these scripts and we hope in the long term to reference these also within technet.  These blog posts serve simply as our first location of sharing them, and this post will be updated once we have the samples hosted within technet.  The scripts themselves are not officially supported, but we will entertain questions and suggestions through this blog until we get it onto technet. 

How do I get started?

First download the zip that contains the scripts from here:

http://sharepoint.microsoft.com/blogs/zach/Script%20Library/Modules/SPModule/SPModule.zip

Next, unpack the zip file onto a share in your environment.  Before you get to use the scripts, you’ll need to make a decision around signing.  By default, Windows PowerShell is configured securely such that it will not run unsigned scripts.  You can choose to either sign them yourself with a self-signed certificate or run Windows PowerShell in a mode where you do not verify signatures.  We do not recommend running Windows PowerShell in this state.  However if you are in an isolated environment, you may choose to do so.  If you follow my last post about signing files, you can use those instructions to sign the entire “Module” in a single command:

function Add-Signing($file){ Set-AuthenticodeSignature $file @(Get-ChildItem cert:\CurrentUser\My -codesigning)[0] }

ls -r -Include ("*.ps1","*.psd1","*.psm1") |%{ Add-Signing $_ }

Please note that if you have not installed SharePoint, then you need to lower the Execution Policy to “AllSigned” using this command: Set-ExecutionPolicy AllSigned. This is done by installing the SharePoint bits so if you’ve already installed this is not needed.

Then open Windows PowerShell as an administrator (right click on the link and select “Run as administrator”).  If you already have SharePoint 2010 installed, you could use the SharePoint 2010 Management Shell instead.  Once the window opens, the first thing we need to do is add the path to the module to your Windows PowerShell module path (presuming you created a folder called “SPModule” on your server):

$env:PSModulePath = “C:\SPModule;” + $env:PSModulePath

Next we need to import the modules:

Import-Module SPModule.misc

Import-Module SPModule.setup

When you import the SPModule.misc module, you will invoke a update check.  In 1.0, this will check a file in the script library above to see if there is a newer version available.  If you are notified that there is, you can go to that location and download the newer version.  Once the Import-Module commands are done, you’re ready to use SPModule.

So, what does SPModule give me?

The 1.0 version of SPModule provides a few major new commands and a number of smaller supporting commands.  Here’s how you can get the list of commands in the module:

Get-Command –Module SPModule.*

The major commands of 1.0 are Install-SharePoint, New-SharePointFarm, Join-SharePointFarm, and Backup-Logs.  They do exactly what their names would lead you to expect (Backup-Logs collects all the logs on the local machine not the whole farm). The rest are for more advanced scenarios or are used by these larger functions—please be careful using commands you don’t understand  Here’s some quick examples to get you started:

Install SharePoint Bits (including Prereqs) on a

Install-SharePoint -SetupExePath “\\servername\SharePoint2010-Beta\setup.exe” -PIDKey “PKXTJ-DCM9D-6MM3V-G86P8-MJ8CY”

New-SharePointFarm –DatabaseAccessAccount (Get-Credential DOMAIN\username) –DatabaseServer “SQL01” –FarmName “TestFarm”

Join-SharePointFarm -DatabaseServer “SQL01” -ConfigurationDatabaseName “TestFarm_SharePoint_Configuration_Database”

Backup-Logs -outp “$env:userprofile\Desktop\SharePointLogs.zip”

Note:  Backup-Logs may have trouble putting the subzip files into the final zip.  We are aware of this issue and are working on this for the next release.  For now, we will detect the situation and keep the subzip files that had a problem”

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s