Archive for January, 2011

SharePoint 2010: PowerShell Script – Create custom List

Scenario:

We need to create PowerShell script to create custom list in a web

Script:

try

{

$weburl = Read-Host “Please enter web url (like : http://sharepoint.ffaiz.com)”

$spweb = Get-SPWeb $weburl

 

$listTemplate = [Microsoft.SharePoint.SPListTemplateType]::GenericList

$spweb.Lists.Add(“My List”,”My list description”,$listTemplate)

write-host “List added in the Web : ” $spweb -foregroundcolor Yellow

$spweb.Dispose()

}

catch [System.SystemException]

{

write-host “Execution stopped due to: “+$_.Message -foregroundcolor Red

}

Advertisements

Leave a Comment

SPWebPartManager.SaveChanges – Parameters

We need to update or change properties of a web part on different pages. For this, wrote a power shell script that updates or change the properties of the webpart. When we try to save the change properties using SPWebPartManager.SaveChanges method, our script through exception

As per MS, SPWebPartManager.SaveChanges takes storageKey as valid parameter but our script through exception every time we run it with the storageKey as parameter.

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.webpartpages.spwebpartmanager.savechanges.aspx

Google it and tried to pass webpart as parameter. Worked like a charm.

Still looking at the documentation and wondering………………….

Leave a Comment