You may have noticed that Central Administration offers you a screen to configure a master Site Directory in SharePoint 2010, but it does not give you the ability to create a site based off of this template through the UI. It appears that this functionality has been removed and is only available under the covers to support SharePoint 2007 upgrades that had this template included.

Once again…. PowerShell comes to the rescue. You can create a Site Directory using the following code snippet.

#———————————————————————————–

# Set the variables

$siteURL = http://lab.ps4sp.com/sites/directory”

$owner = “PS4SPShannon”

$secondOwner = “PS4SPAdministrator”

$template = “SPSSITES#0”

$description = “This site directory was built using PowerShell.”

$name = “Site Directory”

# Create the Site Directory

New-SPSite $siteURL -OwnerAlias $owner -SecondaryOwnerAlias $secondOwner -name $name -Template $template -Description $description

#———————————————————————————–

Once you have your site directory created, you can then use PowerShell to configure your master Site Directory with the following code snippet.

#———————————————————————————–

# Set Site URL

$siteURL = http://lab.ps4sp.com/sites/directory”

# Site Directory Requirements can be one of the following:

# SiteDirectoryCatsOptional, OneSiteDirectoryCatMandatory, or AllSiteDirectoryCatMandatory

$requirements = “AllSiteDirectoryCatMandatory”

#Enforce Listings?

$enforce = $true

# Need to get site and web IDs

$site = get-SPSite $siteURL

$web = get-SPWeb $siteURL

# Get the farm

$farm = get-SPFarm

# Get the Site Directory fromn the Portal Service

$ps = $farm.Services | where {$_.GetType().Name -eq “PortalService”}

$ps.MasterSiteDirectoryLocation = $siteURL

$ps.MasterSiteDirectorySiteId = $site.ID

$ps.MasterSiteDirectoryWebId = $web.ID

$ps.EnforceNewListingForSites = $enforce

$ps.SiteDirectoryEntryRequirements = $requirements

$ps.Update()

$site.Dispose()

$web.Dispose()

#———————————————————————————–

Advertisements

One thought on “SharePoint 2010 and the Site Directory

  1. Hi,

    I am new to power shell and don’tknow how to run these code snippets.I tried but got error.

    I am unable to paste the screen shot here.Can you please give me your email id? So that I can send you screen shot of windows power shell script.

    Thank you,
    Aedla.

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