Monthly Archives: March 2015

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

Advertisements

Custom menu in SharePoint using Taxonomy Term Store Navigation – Programmatically C#

This is a simple example how to access to Taxonomy Term Store properties in SharePoint using c# and create a Custom Menu.

First, create the terms on your Taxonomy Manage Navigation. – Site settings> Site Administration > Term Store Management

To get the Simple Link URL information using C#:

DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[] { new DataColumn("Title"), 
                                       new DataColumn("Url") });
     ...
         foreach (var term in termSet.Terms)
         {
            if (term.IsDeprecated == false)
            {
               try
               {
                 var name = term.Name;
                 var url = term.LocalCustomProperties["_Sys_Nav_SimpleLinkUrl"];
                 dt.Rows.Add(new String[] { name, url });                 
               }
               catch (KeyNotFoundException) { }
             }
           }
       ...
         rptFooter.DataSource = dt; 
         rptFooter.DataBind();

Create ASPX repeater to construct your Menu

<asp:Repeater ID="rptFooter" runat="server">
 <ItemTemplate>
  <li>
  <asp:Button runat="Server" Text='<%# DataBinder.Eval (Container.DataItem, "Title") %>'
  PostBackUrl='<%# DataBinder.Eval (Container.DataItem, "Url") %>' />
 </li>
  </ItemTemplate>
</asp:Repeater>

The full list of Term Set properties on Manage Navigation in SharePoint 2013:

_Sys_Nav_Title: the Navigation Node Title

_Sys_Nav_FriendlyUrlSegment: the Friendly Url, also represented by the FriendlyUrlSegment property of the NavigationTerm class.

_Sys_Nav_TargetUrl: the target URL, also represented by the TargetUrl property of the NavigationTerm class.

_Sys_Nav_TargetUrlForChildTerms: the target URL for child terms, also represented by the TargetUrlForChildTerms property of the NavigationTerm class.

_Sys_Nav_CatalogTargetUrl: the catalog target URL, also represented by the CatalogTargetUrl property of the NavigationTerm class.

_Sys_Nav_CatalogTargetUrlForChildTerms: the catalog target URL for child terms, also represented by the CatalogTargetUrlForChildTerms property of the NavigationTerm class.

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.

Powershell – Script to Deploy Solution on Sharepoint

Many times we need create a script to deploy solutions on SharePoint via Powershell.

So I would like to share my script.

You just need change the Solution Name and Web Application Url.

How to use it:

Save the script in a file with the extension .ps1 > Starts Windows Shell with Administration and run it.

Copy the script below or make download: http://1drv.ms/1HRNeHR

function WaitForJobToFinish([string]$SolutionFileName)
{ 
    $JobName = "*solution-deployment*$SolutionFileName*"
    $job = Get-SPTimerJob | ?{ $_.Name -like $JobName }
    if ($job -eq $null) 
    {
        Write-Host 'Timer job not found'
    }
    else
    {
        $JobFullName = $job.Name
        Write-Host -NoNewLine "Waiting to finish job $JobFullName"
        
        while ((Get-SPTimerJob $JobFullName) -ne $null) 
        {
            Write-Host -NoNewLine .
            Start-Sleep -Seconds 2
        }
        Write-Host "Finished waiting for job.."
    }
}

Add-PsSnapin Microsoft.SharePoint.PowerShell


#-------------------------VARIABLES START-----------------
#default Variables - Always needed
$CurrentDir= split-path -parent $MyInvocation.MyCommand.Definition
$solutionName="YOURSOLUTION.WSP"
$SolutionPath=$CurrentDir + "\"+$solutionName

#variable for dedicated WebApp solutions
$WebAppUrl="HTTP://WEBAPPLICATION:port"

#Only used case features need some Activation/Deactivation
$FeatureName="Feature"
#---------------------VARIABLES END-----------------

#---------------------Deploy Script START-----------------
#Write-Host 'Going to disable feature'
#disable-spfeature -identity $FeatureName -confirm:$false -url $WebAppUrl

#Write-Host 'Going to uninstall feature'
 #uninstall-spfeature -identity $FeatureName -confirm:$false -force
Write-Host 'Going to uninstall solution'
#Comment one of the next 2 script lines
 #1 - For global WSP
 #Uninstall-SPSolution -identity $solutionName -confirm:$false
#2 - For WebApp solutions, I.E. Webparts
Uninstall-SPSolution -identity $solutionName -confirm:$false -WebApplication $WebAppUrl

Write-Host 'Waiting for job to finish'
WaitForJobToFinish

Write-Host 'Going to remove solution'
Remove-SPSolution –identity $solutionName -confirm:$false

Write-Host 'Going to add solution'
Add-SPSolution $SolutionPath

Write-Host 'Going to install solution to all web applications'
#Comment one of the next 2 script lines
 #1 - For global WSP
 #Install-SPSolution –identity $solutionName –GACDeployment -force
 #2 - For WebApp solutions, I.E. Webparts
Install-SPSolution –identity $solutionName -WebApplication $WebAppUrl –GACDeployment -force

Write-Host 'Waiting for job to finish'
WaitForJobToFinish

#Write-Host 'Going to enable Feature'
#Enable-spfeature -identity $FeatureName -confirm:$false -url $WebAppUrl

Remove-PsSnapin Microsoft.SharePoint.PowerShell