Building a SharePoint Farm involves several steps to make sure the site will be utilized by the business users. Governance takes a big part on the design of the Sites(s)

Depending of the size of your farm is conceivable that you will need more than one site colleciton to allocate your business data and to keep security permissions isolated among all the business units. here is where creating programatically all your site collections becomes handy, specially when you don’t have to repeat your self and like to things move agile at all times.

The Following code will be able to create a Database to be used by this site collection, Create a site collection that store the data in the recently created database assign as site collection administratror a specific account, in this case the Farm Admin or the Sharepoint Admin account, with the Template Team Site. Finally run a custom permission level script to be used in this Site Collection and as part of the global compliance security policy of the Farm.

 

$MyDB = New-SPCOntentdatabase -Name “SC_HR” -WebApplication “http://sharepoint2013.com” -MaxSiteCount 1 -WarningSiteCount 0

$site = New-SPSite -URL “http://sharepoint2013.com/depts/hr” -ContentDatabase $MyDB -OwnerAlias “DOMAIN\sharepointadmin” -OwnerEmail “sharepointadmin@DOMAIN.com” -Name “HR” -Template “STS#0”

.\custom_perm_groups.ps1 -path “/depts” -name “/hr” -sitename “HR”

You can verify from Central Admin, In Application Management, View all Site Collections will reflect the name of the user /hr and the new Database linked to it.

dino blog 2 pic 1

The script can be modified to use a different template… in order to display all the Templates available in your SharePoint Farm use the command “Get-SPWebTemplate”

dino blog 2 pic 2

Feel free to replace the used STS#0 “Team Site” to some other template that fits more your needs.

PS C:\> Get-SpWebTemplate

PS C:\> Get-SpWebTemplate

 

Name                 Title

—-                 —–

GLOBAL#0             Global template

STS#0                Team Site

STS#1                Blank Site

STS#2                Document Workspace

MPS#0                Basic Meeting Workspace

MPS#1                Blank Meeting Workspace

MPS#2                Decision Meeting Workspace

MPS#3                Social Meeting Workspace

MPS#4                Multipage Meeting Workspace

CENTRALADMIN#0       Central Admin Site

WIKI#0               Wiki Site

BLOG#0               Blog

SGS#0                Group Work Site

TENANTADMIN#0        Tenant Admin Site

APP#0                App Template

APPCATALOG#0         App Catalog Site

ACCSRV#0             Access Services Site

ACCSVC#0             Access Services Site Internal

ACCSVC#1             Access Services Site

BDR#0                Document Center

DEV#0                Developer Site

DOCMARKETPLACESITE#0 Academic Library

EDISC#0              eDiscovery Center

EDISC#1              eDiscovery Case

OFFILE#0             (obsolete) Records Center

OFFILE#1             Records Center

OSRV#0               Shared Services Administration Site

PPSMASite#0          PerformancePoint

BICenterSite#0       Business Intelligence Center

SPS#0                SharePoint Portal Server Site

SPSPERS#0            SharePoint Portal Server Personal Space

SPSPERS#2            Storage And Social SharePoint Portal …

SPSPERS#3            Storage Only SharePoint Portal Server…

SPSPERS#4            Social Only SharePoint Portal Server …

SPSPERS#5            Empty SharePoint Portal Server Person…

SPSMSITE#0           Personalization Site

SPSTOC#0             Contents area Template

SPSTOPIC#0           Topic area template

SPSNEWS#0            News Site

CMSPUBLISHING#0      Publishing Site

BLANKINTERNET#0      Publishing Site

BLANKINTERNET#1      Press Releases Site

BLANKINTERNET#2      Publishing Site with Workflow

SPSNHOME#0           News Site

SPSSITES#0           Site Directory

SPSCOMMU#0           Community area template

SPSREPORTCENTER#0    Report Center

SPSPORTAL#0          Collaboration Portal

SRCHCEN#0            Enterprise Search Center

PROFILES#0           Profiles

BLANKINTERNETCONT… Publishing Portal

SPSMSITEHOST#0       My Site Host

ENTERWIKI#0          Enterprise Wiki

PROJECTSITE#0        Project Site

PRODUCTCATALOG#0     Product Catalog

COMMUNITY#0          Community Site

COMMUNITYPORTAL#0    Community Portal

SRCHCENTERLITE#0     Basic Search Center

SRCHCENTERLITE#1     Basic Search Center

visprus#0            Visio Process Repository

GLOBAL#0             Global template

STS#0                Team Site

STS#1                Blank Site

STS#2                Document Workspace

MPS#0                Basic Meeting Workspace

MPS#1                Blank Meeting Workspace

MPS#2                Decision Meeting Workspace

MPS#3                Social Meeting Workspace

MPS#4                Multipage Meeting Workspace

CENTRALADMIN#0       Central Admin Site

WIKI#0               Wiki Site

BLOG#0               Blog

SGS#0                Group Work Site

TENANTADMIN#0        Tenant Admin Site

ACCSRV#0             Access Services Site

ACCSRV#1             Assets Web Database

ACCSRV#3             Charitable Contributions Web Database

ACCSRV#4             Contacts Web Database

ACCSRV#6             Issues Web Database

ACCSRV#5             Projects Web Database

BDR#0                Document Center

OFFILE#0             (obsolete) Records Center

OFFILE#1             Records Center

OSRV#0               Shared Services Administration Site

PPSMASite#0          PerformancePoint

BICenterSite#0       Business Intelligence Center

SPS#0                SharePoint Portal Server Site

SPSPERS#0            SharePoint Portal Server Personal Space

SPSMSITE#0           Personalization Site

SPSTOC#0             Contents area Template

SPSTOPIC#0           Topic area template

SPSNEWS#0            News Site

CMSPUBLISHING#0      Publishing Site

BLANKINTERNET#0      Publishing Site

BLANKINTERNET#1      Press Releases Site

BLANKINTERNET#2      Publishing Site with Workflow

SPSNHOME#0           News Site

SPSSITES#0           Site Directory

SPSCOMMU#0           Community area template

SPSREPORTCENTER#0    Report Center

SPSPORTAL#0          Collaboration Portal

SRCHCEN#0            Enterprise Search Center

PROFILES#0           Profiles

BLANKINTERNETCONT… Publishing Portal

SPSMSITEHOST#0       My Site Host

ENTERWIKI#0          Enterprise Wiki

SRCHCENTERLITE#0     Basic Search Center

SRCHCENTERLITE#1     Basic Search Center

SRCHCENTERFAST#0     FAST Search Center

visprus#0            Visio Process Repository

 

The content of the custom_perm_groups is:

 

# URL Configuration to create

param (

[string]$siteURL = “http://sharepoint2013.com“,

[string]$path = $(throw “-path is required.”),

[string]$name = $(throw “-name is required.”),

[string]$sitename = $(throw “-sitename is required.”)

)

# .\my_create_custom_groups.ps1 -path ‘/templates’ -name ‘/my_hr’ -sitename ‘My hr’

$siteURL=[string]$siteURL;

$path=[string]$path;

$subsite=[string]$name;

$sitename=[string]$sitename;

 

# Lets Load the URL in powershell…

$relpath=$path+$subsite

$siteURL=$siteURL+$relpath

Write-Host -ForegroundColor yellow “siteURL [ $siteURL ]”;

 

$site=Get-SPSite $siteURL

$web=$site.RootWeb

 

# Lets Start with Viewers…

$groupName= “$sitename Viewers”

$permissionLevel= “My Viewers”

$description= “$sitename Viewer Group”

Write-Host -ForegroundColor yellow “Creating Group [ $groupName ] with permission level [ $permissionLevel ]”;

 

$newGroup=$web.SiteGroups.Add($groupName,$web.CurrentUser,$null,$description)

$group=$web.SiteGroups[$groupName]

$roleAssignment= New-Object Microsoft.SharePoint.SPRoleAssignment($group)

$roleDefinition= $web.RoleDefinitions[“$permissionLevel”]

$roleAssignment.RoleDefinitionBindings.Add($roleDefinition)

$web.RoleAssignments.Add($roleAssignment);

$web.Update()

 

# Lets add Authenticated Users to the Site.

$user = $web.EnsureUser(‘NT AUTHORITY\AUTHENTICATED USERS’)

$group.Adduser($user)

 

# Lets Work with Members…

$groupName= “$sitename Members”

$permissionLevel= “My Members”

$description= “$sitename Member Group”

 

Write-Host -ForegroundColor yellow “Creating Group [ $groupName ] with permission level [ $permissionLevel ]”;

$newGroup=$web.SiteGroups.Add($groupName,$web.CurrentUser,$null,$description)

$group=$web.SiteGroups[$groupName]

$roleAssignment= New-Object Microsoft.SharePoint.SPRoleAssignment($group)

$roleDefinition= $web.RoleDefinitions[“$permissionLevel”]

$roleAssignment.RoleDefinitionBindings.Add($roleDefinition)

$web.RoleAssignments.Add($roleAssignment);

$web.Update()

 

# Lets Finish with Owners…

$groupName= “$sitename Owners”

$permissionLevel= “My Owners”

$description= “$sitename Owner Group”

Write-Host -ForegroundColor yellow “Creating Group [ $groupName ] with permission level [ $permissionLevel ]”;

$newGroup=$web.SiteGroups.Add($groupName,$web.CurrentUser,$null,$description)

$group=$web.SiteGroups[$groupName]

$roleAssignment= New-Object Microsoft.SharePoint.SPRoleAssignment($group)

$roleDefinition= $web.RoleDefinitions[“$permissionLevel”]

$roleAssignment.RoleDefinitionBindings.Add($roleDefinition)

$web.RoleAssignments.Add($roleAssignment);

$web.Update()

 

$web.Dispose()

$site.Dispose()

 

The Site uses the existing Custom Permissions Levels to create 3 Customized named security groups using those permission levels and assign the role to it. also add the authenticated users to the domain with the default My Viewer permission.

Now we are ready to start using our HR Site Collection with the assurance of 1 Database for the content of this site, with the correct template to be used and with the correct permission levels.

The only thing left to do is to verify the default created permission levels and leave the custom take lead on the permissions not only for this site, but also to all the subsites created underneath their url.

Clicking on Site Settings, Site Permission. The Custom Created Security Groups using also the Custom Created Permission Levels should be.

dino blog 2 pic 3