Skip to main content

Managing site Collections in SharePoint 2010 using cmdlets

In SharePoint 2010 you can manage site collections through Windows PowerShell. You can create new site collections using the New-SPSite cmdlet:

New-SPSite http://SP –OwnerAlias “ds\admmoss” `
-Template “STS#0”

You can retrieve an existing site using the Get-SPSite cmdlet:

Get-SPSite http://SP

You can configure a site collection through the Set-SPWeb cmdlet:

Get-SPSite http://SP | Set-SPSite -SecondaryOwnerAlias “ds\kumar”

And finally, you can remove a site collection using the Remove-SPSite cmdlet:

Remove-SPWeb http://SP -Confirm:$false

Setting the –Confirm switch parameter to $false omits the confirmation returned from PowerShell. If you want to see what happens if you remove a site collection but don’t want to actually remove the site collection you can use the –WhatIf switch parameter.

Remove-SPWeb http://SP –WhatIf

The Cmdlet

New-SPSite [-Url] -OwnerAlias [-AdministrationSiteType ] [-AssignmentCollection ] [-Confirm []] [-ContentDatabase ] [-Description ][-HostHeaderWebApplication ] [-Language ] [-Name ] [-OwnerEmail ] [-QuotaTemplate ] [-SecondaryEmail ] [-SecondaryOwnerAlias ] [-SiteSubscription ] [-Template ] [-WhatIf []] []

The Script

$siteURL = “http://prod.moss.com”

$owner = “ds\admmoss”

$secondOwner = “ds\kumar”

$template = “STS#0″

$description = “This is a sample site that was built using PowerShell.”

New-SPSite $siteURL -OwnerAlias $owner -SecondaryOwnerAlias $secondOwner -name “PowerShell for SharePoint” -Template $template-Description $description

Comments

Popular posts from this blog

How to get SPUser or SPGroup from Person or Group field

You have person or group field in SharePoint list and you want to programmatically get the user or person. The below code to gets SPUser from User or Group field in the list when multiple choice and Groups are not allowed in the field: //get SPUser SPFieldUser userField = (SPFieldUser)item.Fields.GetField("Users"); SPFieldUserValue userFieldValue = (SPFieldUserValue)userField.GetFieldValue(item["Users"].ToString()); SPUser user = userFieldValue.User; This part of code would help you to get SPUser when multiple choice is allowed and groups are not allowed: //Multiple choices are allowed SPFieldUser userField = (SPFieldUser)item.Fields.GetField("Users"); SPFieldUserValueCollection userFieldValueCollection = (SPFieldUserValueCollection)userField.GetFieldValue(item["Users"].ToString()); foreach (SPFieldUserValue userFieldValue in userFieldValueCollection) {     Console.WriteLine("     " + userFieldValue.User.LoginName); } And when group...

SharePoint publishing page scheduling

In SharePoint 2010 publishing enabled team site collection is not showing schedule button in publish ribbon. Solution: Here is how to enable it  though the UI: Locate the SharePoint Server Web site on which you want to enable content approval and item scheduling. Click  Site Actions , click  Site Settings , and then click  Modify Pages Library Settings . Under  General Settings , click  Versioning Settings . Click  Yes  next to  Content Approval , and then click  OK . Click  Manage item scheduling .   Click to enable the  Enable scheduling of items in this list  check box, and then click  OK .

Changing Content Type Hub URL

Change the Hub URL through powershell by using: Set-SPMetadataServiceApplication -Identity " " -HubURI " " For Ex: Set-SPMetadataServiceApplication -Identity "Managed Metadata Service" -HubURI "http://contenttype.Domain.Com" When you try to do this you get this rather scary message: This is SharePoint telling you that this is a major thing so be careful! Essentially all your content types that you have published out will be removed if they can, and you have to republish all of your content types out again which can cause some issue.