Powershell List Operations

Various Powershell List Operations of SharePoint :

#### Create Document Library ####
$spWeb = Get-SPWeb -Identity http://sharepoint/ 
$listTemplate = [Microsoft.SharePoint.SPListTemplateType]::DocumentLibrary 
$spWeb.Lists.Add("My Custom Library","My Custom Library Description",$listTemplate)

#### Add Folder To Library ####
$spDocumentLibrary = $spWeb.GetList("My Custom Library")
$spFolder = $spDocumentLibrary.AddItem("",[Microsoft.SharePoint.SPFileSystemObjectType]::Folder,"My New Folder")
$spFolder.Update()

#### Allow adding Content type to Library - Enable Content Type ####
$spDocumentLibrary.ContentTypesEnabled = $true

#### Add New Content Type to Library ####
$newCTtoAdd1 = $spWeb.ContentTypes["Content Type Name"]
$newCT1 = $spDocumentLibrary.ContentTypes.Add($newCTtoAdd1)

#### Remove Content Type from Library ####
$oldCTtoRemove = $spDocumentLibrary.ContentTypes["Document"]
$spDocumentLibrary.ContentTypes.Delete($oldCTtoRemove.Id)
$spDocumentLibrary.Update()
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