Powershell and SharePoint

  • : Function split() is deprecated in /hsphere/local/home/guruj/guruj.net/modules/filter/filter.module on line 1200.
  • : Function split() is deprecated in /hsphere/local/home/guruj/guruj.net/modules/filter/filter.module on line 1200.
  • : Function split() is deprecated in /hsphere/local/home/guruj/guruj.net/modules/filter/filter.module on line 1200.
  • : Function split() is deprecated in /hsphere/local/home/guruj/guruj.net/modules/filter/filter.module on line 1200.

Unfortunately, I don't know who to thank for this ripper tip about SharePoint:

Any installation of WSS 3.0 or MOSS 2007 is no complete with PowerShell. Why? Because it makes situations like this so easy.

Save the following as SharePoint.ps1:

[System.Reflection.Assembly]::Load("Microsoft.SharePoint, 
Version=12.0.0.0, Culture=neutral, 
PublicKeyToken=71e9bce111e9429c");

function Get-Site($absoluteUrl) {
 return new-object Microsoft.SharePoint.SPSite $absoluteUrl;
}

function Rename-Field($site, $oldTitle, $newTitle) {
 $field = $site.RootWeb.Fields[$oldTitle];
 $field.Title = $newTitle;
 $field.Update;
}

Now the rename function is availble on request:

1> .\SharePoint.ps1
2> $site = Get-Site http://localhost/PlaySite
3> Rename-Field $site "FIO" "Title"

When it comes to SharePoint administration, PowerShell is your new best friend - no compiled code, no deployment issues and you can sign all scripts for use on production servers.

Amen to that!