Powershell in MOSS 2007 – Site Maps

So you have a client that’s running MOSS 2007. With the features and benefits of SharePoint 2013, it’s easy to get quickly frustrated with this old version of SharePoint. Nothing irks me more than forgetting about the lack of PowerShell, each and every time, and spending time looking up STSADM equivalent cmdlets to achieve the same task.

Isn’t there some way I can PowerShell SharePoint 2007?

Yes, but it kind of sucks. I would always recommend using STSADM commands natively when possible, but there really isn’t a good alternative to PowerShell sometimes. Windows SharePoint Services 3.0 and SharePoint Server 2007 do no include built-in cmdlets, but we can do the following if PowerShell is at least installed on the server:

1. Run the following to set the execution policy to allow for scripts to be run locally (this may or may not be reversed/denied via group policy:

2. Load the SharePoint API into you script with the following:

3. Load the MOSS 2007 Script Collection from CodePlex onto the machine HERE

4. Create a new PS1 file with the following format:

The above will run the two referenced PS1 files and keep them in memory preemptively to calling the cmdlets in the script later, and when they are, the console knows where to look for them.

The following can be done via native STSADM to create the same type of output (Note: the enumallwebs command is an STSADM command that is only available in SP ’07 SP2 and above):

Both of these options clearly will work, but the output will be different and some may prefer to stick to STSADM when possible in the older environments.

In the end, this is simply a workaround that allows you to run a small sub-set of your PowerShell scripts that you know and love from SP’13 and SP’10 over a MOSS2007 farm when STSADM commands just fall short.

SharePoint – The local farm is not accessible

Below is an error one may receive when attempting to run SharePoint PowerShell cmdlets through the SharePoint Shell Admin:

“The local farm is not accessible. Cmdlets with FeatureDependencyID are not registered.”


Get-SPContentDatabase : The farm is unavailable.
At line:1 char:1
+ Get-SPContentDatabase
+ ~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (Microsoft.Share...ContentDatabase:
SPCmdletGetContentDatabase) [Get-SPContentDatabase], SPException
+ FullyQualifiedErrorId : Microsoft.SharePoint.PowerShell.SPCmdletGetConte

This error can occur when the user running the commands doesn’t have the proper permissions to the correct back end content databases. The SecurityAdmin roles is necessary to run Shell commands. To resolve this error, either grant the account running the command sharepoint_shell_access and db_owner at minimum to the configuration database in SQL, or login with the SP_Admin account and run with elevated permissions.

If you already have the account granted the above permissions in SQL, you can run the following in a PowerShell console:

Add-SPShellAdmin -UserName DOMAIN\User