Category Archives: PowerShell

SharePoint 2016 – Create Service Accounts using PowerShell script

Hey Everyone!!!

Today i will show you how can you create SharePoint 2016 Service Accounts using PowerShell script following the Best Practices.

The script not only create all the accounts but also create the respectives OU (Organizational Unit):

  • SharePoint Accounts
  • SQL Accounts

Service Accounts:

 Name  Description  Local Rights  Domain Rights
SP_Farm The server farm account is used to perform the following tasks:
-Configure and manage the server farm.
-Act as the application pool identity for the SharePoint Central Administration Web site.
-Run the Microsoft SharePoint Foundation Workflow Timer Service.
SecurityAdmin and DB_Creator rights on the SQL Instance Domain User
SP_Admin The server farm account is used to perform the following tasks:
-Setup
-SharePoint Products Configuration Wizard
Local Administrator on all the SharePoint Servers. SecurityAdmin and DB_Creator rights on the SQL Instance Domain User
SP_Pool The Pool account is used to run the Web Application Pools None Domain User
SP_Services The Services Account is used to run the Service Application Pool None Domain User
SP_Crawl The Default Content Access Account for the Search Service Application None Domain User
SP_Search Service Account to run the SharePoint Search “Windows Service” None Domain User
SP_UserProfiles The User Profile Synchronization Account None Domain User
SP_MySitePool Used for the My Sites Web Application None Domain User
SP_CacheSuperUser Object Cache Service Account. The goals of the object cache are to reduce the load on the computer on which SQL Server is running, and to improve request latency and throughput. These user account must be properly configured to ensure that the object cache works correctly. None.
SharePoint: Must be an account that has Full Control access to the Web application.
Domain User
SP_CacheSuperReader Object Cache Service Account. The goals of the object cache are to reduce the load on the computer on which SQL Server is running, and to improve request latency and throughput. These user account must be properly configured to ensure that the object cache works correctly. None.
SharePoint: Must be an account that has Full Read access to the Web application
Domain User
WF_Service WorkFlow Manager Service Account Local Administrator and SysAdmin rights on the SQL instance. Domain User
SP_MySitePool Used for the My Sites Web Application None Domain User
SP_VisioUser Visio Unattended ID None Domain User
SP_ExcelUser Excel Unattended ID None Domain User
SP_PerfPointUser Performance Point Unattended ID None Domain User
SQL_Admin SQL Admin on the SQL Server. Used to Install the SQL Server. Local Administrator on the SQL Server Domain User
SQL_Services It is the service account for the following SQL Server services: MSSQLSERVER SQLSERVERAGENT None Domain User


Script:

 

$mydom = (get-addomain).distinguishedname 
$password = "pass@word1" | ConvertTo-SecureString -AsPlainText -Force 

$ouNameSP = "SharePoint Accounts"
$oudnSP = "OU=$ounameSP,$mydom" 

$ouNameSQL = "SQL Accounts" 
$oudnSQL = "OU=$ounameSQL,$mydom" 

#----------------------------> Organizational Unit <---------------------------- 

New-ADOrganizationalUnit -Name $OUNameSP -Path $mydom 
Write-Host "OU $OUNameSP Created" -foregroundcolor green 

New-ADOrganizationalUnit -Name $OUNameSQL -Path $mydom 
Write-Host "OU $OUNameSQL Created" -foregroundcolor green 

#-----------------------------> SharePoint 2016 <-------------------------------

$usersArraySP = @("SP_Farm","SP_Admin","SP_Pool","SP_Services","SP_Crawl","SP_Search",
                  "SP_UserProfiles","SP_PortalSuperReader","SP_CacheSuperUser","SP_VisioUser",
                  "SP_PerfPointUser","WF_Service","SP_MySitePool","SP_PortalSuperUser")

foreach ($usp in $usersArraySP) {
        New-ADUser -Name $usp -DisplayName $usp -SamAccountName $usp -AccountPassword $password 
        -ChangePasswordAtLogon $false -PassThru -PasswordNeverExpires $true -Path $oudnSP 
        Write-Host "$usp Created" -foregroundcolor green
 }

#----------------------------------> SQL <--------------------------------------
$usersArraySQL = @("SQL_Admin","SQL_Service")

foreach ($usql in $usersArraySQL) {
       New-ADUser -Name $usql -DisplayName $usql -SamAccountName $usql -AccountPassword $password 
       -ChangePasswordAtLogon $false -PassThru -PasswordNeverExpires $true -Path $oudnSQL
       Write-Host "$usql Created" -foregroundcolor green
 }

 

Thanks

Fábio Carvalho
SharePoint Consultant
|create|it|

Advertisements

SharePoint Templates – Understand the differences

Hey Everyone!

Today i will talk about SharePoint Site Templates, and explain the main difference between each template and how it is extremely important to have in mind what each version can offer you in terms of features and capabilities to meets your business needs.

So the first thing you must know is there are 3 main categories of templates:

  • Collaboration
  • Enterprise
  • Publishing

For each category you have different site types, when you create a new site the “site type” define the purpose of the new one and includes all the features.

Collaboration site templates:
  • Team Site – This template can be  used when you what organize and share information with your team or project members, this template includes lists and libraries for: Share Documents, Announcements, Calendars, Links, Tasks, Discussion Board.

  • Blog Site – This template can be  used when you what announce company announcements, post ideas, observations, expertise with your team organization. It is easy  start a new blog, including Comments and Links.

  • Project Site – With this site template it is so much easy to manage your projects, it is an upgrade of Team Site but this one have more functionalities including Projects Summary, Task Lists. Calendar Sharing, Task Scheduler, Visual Timeline of the Project’s Tasks.

  • Community Site – It is more than a Blog Site, this template you can create a place where you can discuss topics that you have in common with others team members, it is more easy and you have more benefits over email, with a full retention of discussion history in compliance with corporate guidelines.
Enterprise site templates:
  • Document Center Site – This template is indicated when you want manage large numbers of documents, it is more easy create folder structures and use file versions also you can use workflows to control document life cycles.

  • Records Center Site – This template is indicated when you what organize, store and manage records such as legal or financial documents, the site includes versioning, auditing, metadata management, eDiscovery feature to help manage records more effectively.

  • Business Intelligence (BI) Center Site – This is one of my favorite site template, you can store, manage, share and view business reports, scorecards and dashboards. This template includes Performance Point Service, a service very important to build dashboards inside of SharePoint.

  • Search Center (Enterprise or Basic) Site – A template dedicated to search features where you can search and apply refiners to your search results.

Publishing site templates:
  • Publishing Site – The template indicated when you want create enterprise intranets, communication portals and public websites. This template by default have publishing features enable including Page Layouts, Column Types, Web Parts, Lists and very important Documents and image libraries for storing web publishing assets.

  • Publishing Site with Workflow – Use the Publishing site with workflow to publish web pages on a schedule by using approval workflows. It includes document and image libraries for storing web publishing assets.

  • Enterprise Wiki – It is a publishing site for sharing and updating large volumes of information across an enterprise,  your organization can centralized knowledge repository.

The follow table show all Templates available for each SharePoint version.

Category
Site Type
Template ID
Site Collection
Site
SharePoint Server 2013
SharePoint Foundation 2013
SharePoint Server 2016
SharePoint Online
Collaboration Team STS#0 Yes Yes Yes Yes Yes Yes
Collaboration Blog BLOG#0 Yes Yes Yes Yes Yes Yes
Collaboration Project PROJECTSITE#0 Yes Yes Yes No Yes Yes
Collaboration Community SPSCOMMU#0 Yes Yes Yes No Yes Yes
Enterprise Document Center BDR#0 Yes Yes Yes No Yes Yes
Enterprise Records Center OFFILE#1 Yes Yes Yes No Yes Yes
Enterprise Business Intelligence Center BICenterSite#0 Yes Yes Yes No Yes Yes
Enterprise Enterprise Search Center SRCHCEN#0 Yes Yes Yes No Yes Yes
Enterprise Basic Search Center SRCHCENTERLITE#0 No Yes Yes No Yes Yes
Publishing Publishing Site BLANKINTERNET#0 No Yes Yes No Yes Yes
Publishing Publishing Site with Workflow BLANKINTERNET#2 No Yes Yes No Yes Yes
Publishing Enterprise  Wiki ENTERWIKI#0 No Yes Yes No No Yes

 

Also you have different types of site template variation, the following table show ALL the Template ID available, and you can you use powershell command to create them.

New-SPWeb http://createIT/blog -Template "BLOG#0"
Template ID
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
ACCSRV#1 Assets Web Database
ACCSRV#3 Charitable Contributions Web Database
ACCSRV#4 Contacts Web Database
ACCSRV#5 Projects Web Database
ACCSRV#6 Issues Web Database
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 Server Personal Space
SPSPERS#3 Storage Only SharePoint Portal Server Personal Space
SPSPERS#4 Social Only SharePoint Portal Server Personal Space
SPSPERS#5 Empty 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
BLANKINTERNETCONTAINER#0 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
SRCHCENTERFAST#0 FAST Search Center
VISPRUS#0 Visio Process Repository

 

Fonts:
Using templates to create different kinds of SharePoint sites
SharePoint templates and their IDs

Thanks

Fábio Carvalho
SharePoint Consultant
|create|it|

SharePoint – Export all solutions wsp using PowerShell script

Hey Everyone,

Today i will post a script very helpful when you are on Migration steps and you need export all wsp solutions.

 

$dirName = "C:WSP"
if (!(Test-Path -path $dirName))
{
New-Item $dirName -type directory
}
Write-Host Exporting solutions to $dirName
foreach ($solution in Get-SPSolution)
{
    $id = $Solution.SolutionID
    $title = $Solution.Name
    $filename = $Solution.SolutionFile.Name
    Write-Host "Exporting ‘$title’ to …$filename" -nonewline
    try {
        $solution.SolutionFile.SaveAs("$dirName$filename")
        Write-Host " – done" -foreground green
    }
    catch
    {
        Write-Host " – error : $_" -foreground red
    }
}

Thanks

Fábio Carvalho
SharePoint Consultant
|create|it|

Script to Change Page Layout on Publishing Pages – PowerShell

If you want change pagelayouts, you can use this usefull script.

$spWeb = Get-SPWeb("http://fcsharepoint")
$pWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($spWeb)
$pSite = New-Object Microsoft.SharePoint.Publishing.PublishingSite($spWeb.Site);

$siteLayouts = $pSite.GetPageLayouts($false)
$myLayout = $siteLayouts["/_catalogs/masterpage/fcPageLayout.aspx"]
$query = New-Object Microsoft.SharePoint.SPQuery
$query.ViewAttributes = "Scope='RecursiveAll'"

$pages = $pWeb.GetPublishingPages($query)

foreach ($page in $pages)
{
     if ($page.ContentType.Name -eq "Folder")
     {
         continue
     } 
     $page.Layout = $myLayout
     $page.update()
     $page.ListItem.File.Publish("")
     $page.ListItem.File.Approve("")
}
$spWeb.Dispose()

Enable STS Session Cookie & LogonTokenCacheExpirationWindow in SharePoint

Enable STS Session Cookie

$sts = Get-SPSecurityTokenServiceConfig
$sts.UseSessionCookies = $true
$sts.Update()

LogonTokenCacheExpirationWindow for the SharePoint STS is 10 minutes. The relying party by default it sets the token lifetime in ADFS to be 2 minutes.

LogonTokenCacheExpirationWindow in SharePoint

$sts = Get-SPSecurityTokenServiceConfig
$sts.LogonTokenCacheExpirationWindow = (New-TimeSpan minutes 1)
$sts.Update()

Then do an IISRESET

Add users to SharePoint Group using PowerShell

You can Add user on SharePoint’s Group using Powershell, to do that you just need to know two things:

  • User domain name -> domain\User
  • Group’s name – you can check this on the following post – http://wp.me/p4Hadm-45

Then you can run the following powershell script:

$site=get-spsite http://fcsharepoint

$web=$site.RootWeb

$web.SiteGroups |select name

$user=$web.EnsureUser("LOCALDOMAIN\FCShareUser")

$group=$web.SiteGroups["FCSharepoint Members"]

$group.AddUser($user)

List all Groups and all Users SharePoint – PowerShell

The scrit below list all Groups and all Users at sitecollection of SharePoint.

$site = Get-SPSite http://fcsharepoint

$groups = $site.RootWeb.sitegroups

foreach ($grp in $groups)
{
    "Group: " + $grp.name;
     foreach ($user in $grp.users)
     {
         " User: " + $user.name
     }
}
$site.Dispose()

Listing / Installing / Uninstalling / Enabling / Disabling Features on Farm, Site Collection and Site – Sharepoint Powershell

Listing Features

Show all the features on the farm:

 Get-SPFeature | Sort -Property DisplayName

Show all the features on the Farm grouped by scope in a table use:

 Get-SPFeature | Sort -Property DisplayName, Scope | FT -GroupBy Scope DisplayName

Show all features for a Web Application:

 Get-SPFeature -WebApplication http://webapplication

Show all features for a Site Collection:

 Get-SPFeature -Site http://sitecollection

Show all features for a Site:

 Get-SPFeature -Web http://siteurl

Enabling and Disabling Features

To disable and enable features:

Disable-SPFeature

 Disable-SPFeature -Identity "NameOfFeature" -URL http://url

Enable-SPFeature

 Enable-SPFeature -Identity "NameOfFeature" -URL http://url

Installing and Uninstalling Features

To install and uninstalling a feature you need to specify the name of the folder that your feature contains:

Install-SPFeature
 Install-SPFeature "FeatureFolderName"
Uninstall-SPFeature
Uninstall-SPFeature "FeatureFolderName"

Creating Subsites using Powershell Script & List of SharePoint 2013 Template Sites

How to create a sub site using Power Shell scripts:

To add a new subsite use the New-SPWeb powershell command

New-SPWeb –url <new site url> -name <new site name> -template <template name>

Additional cmdlet which can be used: 

AddToTopNav: Add the site to the top navigation bar 

 UseParentTopNav: Use the top navigation bar from the parent

 AddToQuickLaunch: Add the new site to the Quick Launch section

– UniquePermissions: Break parent permissions, and will create for new Subsite.

Example:

$WebAppUrl="http://fcSharePoint:5000"

#->SubSite1<-
$SubSiteTitle1 = "This is SubSite  - 1 - Title"
$SubSite1Url = "SubSite1"
New-SPWeb –url $WebAppUrl"/"$SubSite1Url -name $SubSiteTitle1 -Template "STS#0" 
–AddToTopNav –UniquePermissions –UseParentTopNav
Write-Host 'Create new SubSite:' $SubSiteTitle1 '-> Url:'$WebAppUrl"/"$SubSite1Url

#->SubSite2<-
$SubSiteTitle2 = "This is SubSite - 2 - Title"
$SubSite2Url = "SubSite2"
New-SPWeb –url $WebAppUrl"/"$SubSite2Url -name $SubSiteTitle2 -Template "STS#0" 
–AddToTopNav –UniquePermissions –UseParentTopNav
Write-Host 'Create new SubSite:' $SubSiteTitle2 '-> Url:'$WebAppUrl"/"$SubSite2Url

#->SubSite3<-
$SubSiteTitle3 = "This is SubSite - 3 - Title"
$SubSite3Url = "SubSite3"
New-SPWeb –url $WebAppUrl"/"$SubSite3Url -name $SubSiteTitle3 -Template "STS#0" 
–AddToTopNav –UniquePermissions –UseParentTopNav
Write-Host 'Create new SubSite:' $SubSiteTitle3 '-> Url:'$WebAppUrl"/"$SubSite3Url

List of SharePoint 2013 Template Sites:

Template ID 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
ACCSRV#1 Assets Web Database
ACCSRV#3 Charitable Contributions Web Database
ACCSRV#4 Contacts Web Database
ACCSRV#5 Projects Web Database
ACCSRV#6 Issues Web Database
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 Server Personal Space
SPSPERS#3 Storage Only SharePoint Portal Server Personal Space
SPSPERS#4 Social Only SharePoint Portal Server Personal Space
SPSPERS#5 Empty 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
BLANKINTERNETCONTAINER#0 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
SRCHCENTERFAST#0 FAST Search Center
visprus#0 Visio Process Repository

Template IDT

Change MasterPage of SharePoint Sites via PowerShell

On SharePoint Server, you can change MasterPage using Powershell Script.

First, you need check if your masterpage file that there you want apply is in a correctly library.

Go to Settings > Site Settings > Web Designer Galleries > Masterpage and Page Layout.

If you have the file on directory you just need run the script bellow.

      $web = Get-SPWeb siteurl
      $web.MasterUrl = “masterpagerelativeurl”
      $web.Update()
      $web.Dispose()

Examples:

foreach ($site in get-spsite -url http://fcsharepoint*) {
$web = Get-SPWeb $site
$web.CustomMasterUrl = “/_catalogs/masterpage/MasterPage.master”
$web.Update()
}
$web = Get-SPWeb http://fcsharepoint/sites/test
$web.MasterUrl = "/sites/test/_catalogs/masterpage/customMasterPage.master"
$web.Update()
$web.Dispose()

If something went wrong verify if Feature – SharePoint Server Publishing Infrastructure is Enable.