PowerShell on SharePoint 2007
On October 10, 2017 (just 21 days before my birthday, in case you'd like to get me a present), SharePoint Server 2007 will reach End-of-Life. 99.999% of you have already migrated off this platform. If, like some of my customers, you've been running into issues trying to migrate your users' content, you may find yourself in need of some guidance in performing various tasks to enable your migration. Such was the case last week, when I was asked to create a script that would automate the check-in process for several thousand documents so that they could be migrated.
If your initial thought is "Gee, I wish I could use PowerShell to accomplish this in SharePoint 2007," you're in luck! As my good friend Praveen Hebbar points out in his blog post, It's possible to run PowerShell scripts against MOSS 2007. For those that would prefer not to jump to his post, I've replicated it here:
-
-
If you are running MOSS 2007 on Windows Server 2003, then you have to download and install PowerShell. Windows Server 2008 natively supports PowerShell.
Set the Execution Policy to RemoteSigned. You can check it by running the Get-ExecutionPolicy cmdlet. The default execution policy for PowerShell is “Restricted” (commands only, not scripts).
# All scripts running locally are allowed Set-ExecutionPolicy RemoteSigned
This means downloaded scripts must be signed by a trusted publisher before they can be run.
You need to load the SharePoint assemblies with the following command:
# Load the SharePoint assemblies [Void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
-
A bunch of PowerShell scripts are available here.
For those of us who haven't used SharePoint 2007 since 2010's release date, this is great news. Using Praveen's guidance, my customer was able to cobble together a script which they anticipated would solve their problem. However, when trying to run the script, they encountered the following error:
New-Object : Exception calling ".ctor" with "1" argument(s): "The Web application at [CENSORED] could not be found. Verify that you have typed the URL correctly. If the URL should be serving existing content, the system administrator may need to add a new request URL mapping to the intended application."
The reason for this is that older versions of SharePoint (in this case, MOSS 2007) requires PowerShell V2 for running PowerShell cmdlets. As my grandfather used to say, "I'll bet you dollars to donuts" that you're running a newer version of PowerShell. To determine whether this is the case, you can simply use $PSVersionTable.PSVersion to determine your version. Once you've been able to ascertain that this is the case, you can simply force PowerShell to run as V2 by using powershell -version 2.
PS C:\> $PSVersionTable.PSVersion
Major Minor Build Revision
----- ----- ----- --------
4 0 -1 -1
PS C:\> powershell -version 2
PS C:\>