Showing posts with label Powershell. Show all posts
Showing posts with label Powershell. Show all posts

Friday, September 20, 2013

Configure State Service in SharePoint 2013

The state service is a shared service for SharePoint to store temporary data.
Also the state services cannot be installed from the GUI.

Note, Run as Administrator opening the SharePoint Management Shell

The following Powershell commands will set up the state services with your own database name.

New-SPStateServiceApplication -Name "State Service Application"
Get-SPStateServiceApplication| New-SPStateServiceApplicationProxy –defaultproxygroup
Get-SPStateServiceApplication| New-SPStateServiceDatabase -Name "State_Service_DB"
Get-spdatabase | where-object {$_.type -eq "Microsoft.Office.Server.Administration.StateDatabase"} | initialize-spstateservicedatabase


Saturday, September 14, 2013

List all the databases currently used by SharePoint 2013 farm using Powershell


Powershell commands to 
1. Gets a list of all the databases currently used by SharePoint 2013 farm

Get-SPDatabase | Sort-Object Name | Format-Table Name

2. Gets a list of the content databases

Get-SPContentDatabase | Sort-Object Name | Format-Table Name

Tuesday, November 20, 2012

Enable the SharePoint Server Publishing Feature in SharePoint 2010 using Powershell

To use the SharePoint Server publishing feature in a SharePoint site, we need to activate the PublishingSite in site collection level as a first step and finally activate the publishing web to all webs in that site collection.


Script to Activate the SharePoint Server Publishing Feature

#Step 1: The SharePoint Server Publishing Infrastructure Feature needs to be enabled in site collection level
$PublishingSitefeature = Get-SPFeature PublishingSite #where the PublishingSite is the inernal name of the SharePoint Server Publishing Infrastructure Feature
write-host "The feature name is " $PublishingSitefeature.DisplayName
$siteCollection = Get-SPSite $siteUrl #Into Site Collection level
write-host "Activating " $PublishingSitefeature.DisplayName " on "  $siteCollection.Url
Enable-SPFeature $PublishingSitefeature -Url $siteCollection.Url #Enable the feature to the site collection
write-host "Activated " $PublishingSitefeature.DisplayName " on "  $siteCollection.Url
$siteCollection.Dispose()

#Step 2: Then enable the SharePoint Server Publishing feature to all webs in Site collection.
$siteCollection = Get-SPSite $siteUrl #Into Site Collection level
$siteCollection | Get-SPWeb -limit all | ForEach-Object{
write-host "Activating the PublishingWeb feature on " $_.Url
Enable-SPFeature -Identity "PublishingWeb" -Url $_.Url #where the PublishingWeb is the internal name of the SharePoint Server Publishing feature
write-host "Activated the PublishingWeb feature on " $_.Url
}
$siteCollection.Dispose()

#Note: Publishing feature needs to be enabled in site collection before enabling it to all the webs

Remove a WebPart from SharePoint Pages using Powershell

The following script is very useful in removing a webpart from SharePoint page.


if ( (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null )
{
    Add-PSSnapin Microsoft.SharePoint.PowerShell
}

$spWeb = Get-SPWeb $siteUrl -ErrorAction Stop

#Declare the absolute path to the SharePoint page
$pagePath = "/SitePages/Home.aspx"
$pageUrl = $siteUrl + $pagePath
write-host "Processing site: ", $siteUrl
write-host "Processing page: ", $pageUrl

#Initialise the Web part manager for the specified profile page.
$spWebPartManager = $spWeb.GetLimitedWebPartManager($pageUrl, [System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)

#List all the Webparts in the specified page
foreach ($webpart in $spWebPartManager.WebParts)
{
    write-host $siteUrl +": Existing Web part - " + $webpart.Title + " : " + $webpart.ID
    break;
}
#Remove the Share Documents Web part from that page
foreach ($webpart in ($spWebPartManager.WebParts | Where-Object {$_.Title -eq "Shared Documents"}))
{
    write-host $siteUrl +": Existing Web part - " + $webpart.Title + " : " + $webpart.ID
    $webpart1 = $webpart
    break;
}
#Delete the existing webpart
$spWebPartManager.DeleteWebPart($spWebPartManager.WebParts[$webpart1.ID])
write-host "Deleted the existing Shared Document web part."

$spWeb.Dispose()

Delete Navigation nodes using Powershell in SharePoint 2010 QuickLaunch.

This script is used to delete the navigation nodes in the  SharePoint Quick Launch (Left side - navigation links) in the site.


if ( (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null )
{
    Add-PSSnapin Microsoft.SharePoint.PowerShell
}


$spWeb = Get-SPWeb $siteUrl -ErrorAction Stop
Foreach($node in ($spWeb.Navigation.QuickLaunch)){
write-host "The node title is "$node.Title
$node.Delete()
}
$spWeb.Dispose()