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


Rename Admin Content database in SharePoint 2013

Normally, When we install SharePoint 2013 using SharPoint Configuration wizards the Central Administration Web Application is provisioned with
the database. The admin database name is generated automatically with a GUID.
For example, in my instance it has created with the following name,
Admin_Content_bbceaf91-431d-461a-9c91-c89ed4c21e59

The following steps will help the SharePoint Administrator to rename the Admin content database to a proper format.

Open the SharePoint Management Powershell (Run AS Administrator)

List of Commands to be used to rename the Central Admin Database
1. Create a new Central Administration Content Database
New-SPContentDatabase -Name SharePoint_AdminContent -WebApplication http://centralAdminsite:Port

2. Get a list of Central Administration Content Databases
Get-SPWebApplication -Identity http://centraladminsite:port | Get-SPContentDatabase | Select Id, Name, WebApplication
| Format-List

Copy database content
Get-SPSite -ContentDatabase oldadmin content database ID GUID | Move-SPSite -DEstinationDatabase newadmindatabase ID Guid

Ensure you can access the central admin web site in Internet Explorer.

Delete the old database
Remove-SPContentDatabase oldadmin content database ID GUID

Confirm the old database has been removed from SharePoint
Get-SPWebApplication -Identity http://centraladminsite:port | Get-SPContentDatabase |Select Id, Name,
WebApplication | Format-List

Sunday, September 15, 2013

Migrate SQL 2008R2 SP2 to SQL 2012 SP1 in SharePoint 2013

I have created three tier architecture of SharePoint 2013 with the following details (WFE1 + APP1 + SQL1) 
where 
SQL1 - Win 2008R2 + SQL 2008R2 Enterprise edition
WFE1 - SharePoint 2013 Web front end
APP1 - SharePoint 2013 Application Server (with extra service applications like State service, Word automatin service etc).

Tested with the following scenarios

Test 1: -- Failed
1. Created a VM of SQL 2 with SQL 2012 SP1 on Win 2008 r2
2. Disconnected the Farm on APP1 and WFE1 using SharePoint product configuration wizard.
3. Stopped all the services, detach and attach all the respective databases from SQL1 to SQL2.
4. Tried to attach the config database from the new server SQL 2, Failed. Doesn't allow to proceed at all.. 
Tried lots of workarounds, but really failed, then noticed the reason that while the configuration database is created, SharePoint hardcodes the SQL server details with the versions on the database records and in the internal registry of the application server.

Test2: -- Failed
1. Reverted to the fresh snapshot of SQL2 with fresh SQL 2012 SP1 install & WFE1, APP1 servers to the normal state.
2. Stopped all the services on the APP1 and WFE1
3. Take all the respective databases offline in SQL1, then detach and attach the databases to SQL2.
4. Create Client SQL alias in APP1 and WFE1 servers to point to SQL 2., iisreset
5. This test also failed, as it throwed the same errors like the above ( as expected, just wanted to try it out)
 
Test 3: Sucessful
1. Ensure to have passphrase and get all the APP, WFE server configuration details using powershell script/also hidden information like port details etc.
2. Disconnect the APP1 and WFE1 from the farm from SQL1
3. Then Create a new farm on the SQL2 server using psconfig. 
The above will create fresh SharePoint config, Admin content for central Administration databases.
4. Then move all the contents databases and service application databases and properly configure to respective web application and service applications.
That's the reason, why we need all the information to ensure everything is configured correctly.

Test 4: -- Successful
1. Recreated the same server of SQL 1 to SQL3 with the same fresh installs.
2. Stops all the services on the SharePoint APP1 and WFE1
3. Then detach and attach all the databases from the SQL1 to SQL3.
4. Created Client SQL alias in APP1 and WFE1 server to point from SQL1 to SQL3 server.
5. Then iisreset, Ensure everything works with the connections with SQL3.
6. Then stop all the services on the APP1 and WFE1.
7. Upgrade the SQL3 to SQL 2012 using upgrade wizard.
8. After installation completes,irestart all the servers
9. Ensure it works successfull. Tested, works fine

Although SharePoint 2013 is compatible with SQL 2008 R2 SP2 and SQl Server 2012, it doesn't like to detach and attach method for the configuration databases within the sql versions. So make a wiser choice of selecting the newest SQl version.

Saturday, September 14, 2013

Find Current Location of Data and Log File of All the Database using sql command

The sql command to list the current data and log file locaiton is as follows.

select name, physical_name As current_file_locaton from sys.master_files


Following is the output of files used by my SQL Server instance.




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()