Monday 4 May 2015

Quickly restore a deleted site collection through Power Shell Command

One day I received a call from a frantic customer who accidentally deleted a very valuable site and needed it restored ASAP. I was still new, so their panic started to make me panic - especially when I heard that the deleted site had also been emptied from the Recycle Bin and the process to restore a site from SQL takes more time than we had. 

Luckily, one of my team members was watching over my shoulder and said, “Use PowerShell to find the site and then restore it - it shouldn't even take 10 minutes."

Brilliant! Here are the PowerShell commands to restore a deleted SharePoint site:

Get-SPDeletedSite | select Path , siteid
(This will generate a list of all deleted sites and their GUIDs as seen below) 
Then, run the command:
      Restore-SPDeletedSite -Identity (SITE ID)

(in this case,    
Restore-SpDeletedSite –Identity 4bff0c0e-4d56-4fec-8174-a60a16daeaac)
 This final command will restore the site


Finding a Correlation ID error through Power Shell Command

One frustrating error SharePoint users will occasionally experience is the dreaded 'red X' with a cryptic correlation ID error. When that happens, the SharePoint Administrator must perform the equally frustrating task of looking through the logs to find the cause of the error. 
  
Wouldn't it be nice if there was a command that will search the log files for the correlation ID?  The command Merge-SPlogfile will automatically search the logs for the error ID. Better than that, the command will search ALL the servers in the farm and place a log file on the server that you will the command.  Here is an example of the the Merge-SPlogfile command

Merge-SPLogFile -Path -Correlation <Guid>
(I typically run the command like this using the Correlation ID from sample error above.)

Merge-SPlogfile –Path c:\log.log –Correlation ba05e237-0680-403a-b9f6-e49f96ac55d4
(That will place a .log file on the C drive of the server which will only contain errors with the correlation ID.)

Wednesday 29 April 2015

Manged Metadata Service or Connection is not available

After installing latest Cumulative Update (Nov CU) in SharePoint 2013 farm, I was able to successfully upgrade the environment and PSConfig completed successfully. While testing sites after upgrade, I notice Managed Navigation for any site is not working any more. I was able to get in to Managed Metadata Service Application using central administration but when I click on Navigation option on site settings.aspx page, Term Set and Terms were not showing there. If I try to go to the term store management from site settings.aspx page I was getting
The Managed Metadata Service or Connection is currently not available. The Application Pool or Managed Metadata Web Service may not have been started. Please Contact your Administrator
Solution:
I tried all solutions mentioned here but did not work. After some more digging in to log files I find some permissions related logs for SharePoint resources. I ran
PSConfig.exe -cmd secureresources
and that resolved the issues.

Expired Session are not being deleted

On Central Administration page I got this warning for expired sessions .One of the many reasons for these sessions are created if you are using info path form services. These sessions are supposed to be deleted after some time I think its once in 24 hours but in case if it’s not being deleted you can delete them manually or create a job in SQL and set it to run once a day.

First method is you can fire this procedure manually that will clean up all the expired sessions. To do this open up your SQL. Look for the Session State Service ——- data base, expand Programmability, expand Stored Procedure, and right click on dbo.DeleteExpiredSessions click on Execute Stored Procedure.

Go back to CA and Click on Re analyze Now button it will disappear. If not open up a new IE session and try again
Second method is you can create a job that will run automatically and clean up those sessions for you here is a nice article written by Dave to create a job.
There is a TechNet article about this warning but it did not help me much . You can take a look at that: http://technet.microsoft.com/en-ca/library/ff805085.aspx

I spend lot of time searching on the internet to find a solution for this issue but could not find anywhere finally I had to contact Microsoft and thanks to Roop Kumar who help me to find this solution.


I had this issue on our project server 2010 when user try to delete some project it is deleted from but still shows up in list of projects. On the job queue page it also shows me that job was 7% or sometimes 20% complete with error below. After looking more I find out that project still reside in the published data base, it was deleted only from the draft data base.
rejectedTimesheetLines (System.Guid) :
Item value = ’55df1eea-5d6c-0ff0-0a26-979bed281388′ :
Error: id=’10000′ name=’GeneralItemDoesNotExist’ uid=’452d0181-26c5-42c1-9588-b3bd2b9ca4b7′
Error: id=’10000′ name=’GeneralItemDoesNotExist’ uid=’6fc2cb49-4072-4e55-8c6d-87faeb07c56e’
Error: id=’10000′ name=’GeneralItemDoesNotExist’ uid=’9d9ccd87-09c6-461b-b784-52330bba6e13′
Error: id=’10000′ name=’GeneralItemDoesNotExist’ uid=’60b5c3d9-8c0b-421b-a7c4-f1dcd6f94ea5′
Error: id=’10000′ name=’GeneralItemDoesNotExist’ uid=’043160c3-cc42-4bdf-9bf6-25ce1a0b6b31′
Error: id=’10000′ name=’GeneralItemDoesNotExist’ uid=’956964e8-ae10-4353-a0a6-6c7ae4e501bf’
Item value = ‘8c9b1235-b444-0eb5-2306-9c0cb357bc34′ :
Error: id=’10000′ name=’GeneralItemDoesNotExist’ uid=’4cb03352-517b-4b3d-be23-5d312a3e628b’
Error: id=’10000′ name=’GeneralItemDoesNotExist’ uid=’8c2dec26-e1f0-4f54-b4fa-7e99c3c24af3′
Error: id=’10000′ name=’GeneralItemDoesNotExist’ uid=’08555499-4e94-4d45-913d-cbdc5924bda7′
Error: id=’10000′ name=’GeneralItemDoesNotExist’ uid=’2770e31b-6c44-4607-aeb5-9689adf85534′
Error: id=’10000′ name=’GeneralItemDoesNotExist’ uid=’bedd69f6-8a84-4e6b-b990-6e2cc83f8da1′
Error: id=’10000′ name=’GeneralItemDoesNotExist’ uid=’b5401565-5a62-4e5b-a571-da25919335cb’
General Error:
ProjectDeleteFailure (23006). Details: id=’23006′ name=’ProjectDeleteFailure’ uid=’1fb2ee32-538b-47d3-854b-d56f30b6e5b0′ projectuid=’93c03f72-1736-4961-ad3f-5062067f82b0′ messagetype=’Microsoft.Office.Project.Server.BusinessLayer.QueueMsg.AdjustTimeSheetForDeletedProjectMessage’ messageID=’6′ stage=” blocking=’Undefined’.
Queue:
GeneralQueueJobFailed (26000) – ProjectDelete.AdjustTimeSheetForDeletedProjectMessage. Details: id=’26000′ name=’GeneralQueueJobFailed’ uid=’9c824957-4e4b-4fd5-be58-af24b4e2d467′ JobUID=’cb13ed49-b781-45b9-b65a-15336803b5e8′ ComputerName=’SGPROJECT’ GroupType=’ProjectDelete’ MessageType=’AdjustTimeSheetForDeletedProjectMessage’ MessageId=’6′ Stage=”. For more details, check the ULS logs on machine SGPROJECT for entries with JobUID cb13ed49-b781-45b9-b65a-15336803b5e8.
This is due to the bad time sheet lines. It can also be some task that was not completed or rejected or corrupted.
Solution:
First you need to find out the Proj_UID  for the project that is causing this issue by running this query against your Published data base (ProjectServer_Published)
select * from MSP_PROJECTS where PROJ_NAME like’Name of your Project’
Copy Proj_UID from the column here
Run this query to delete the time sheet lines that are causing issue you need to paste proj_uid in the red text .
delete MSP_TIMESHEET_ACTUALs where ts_line_UID IN (SELECT DISTINCT A.TS_LINE_UID FROM MSP_TIMESHEET_ACTIONS A
INNER JOIN MSP_TIMESHEET_LINES L ON A.TS_LINE_UID = L.TS_LINE_UID WHERE A.TS_ACTION_ENUM = 1 AND L.PROJ_UID = ‘paste Guid here copied in the step above’)
delete MSP_TIMESHEET_LINES where ts_line_UID IN (SELECT DISTINCT A.TS_LINE_UID FROM MSP_TIMESHEET_ACTIONS A
INNER JOIN MSP_TIMESHEET_LINES L ON A.TS_LINE_UID = L.TS_LINE_UID WHERE A.TS_ACTION_ENUM = 1 AND L.PROJ_UID = ‘paste Guid here copied in the step above’


Try to delete the project now.

Restart Microsoft SharePoint Foundation Web Application Service. Stuck at Stopping.


I wanted to share some information in case you are planning to restart “Microsoft SharePoint Foundation Web Application” service or any other service and got stuck with status showing “Stopping” you can use power shell command mentioned below
I had a situation when “Microsoft SharePoint Foundation Web Application” service was Showing “Stopping” status for more than 7 hours and even reboot and IIS reset did not do anything. I was able to restore service in normal condition using command mentioned below.
Note: In case you are planning to restart “Microsoft SharePoint Foundation Web Application” service better back up your IIS and Virtual directory folder to be on the safe side.
Credit goes to Trevor Seward from TechNet who shared this trick  and show easy way to restore/provision virtual directory folder.

If you have the same situation where some service is stuck use power shell to stop it
$svc = Get-SPServiceInstance | where {$_.TypeName -like "*Foundation Web*"}
$svc.Status = "Offline"
$svc.Update()

You can use PowerShell to start it again
$svc = Get-SPServiceInstance | where {$_.TypeName -like "*Foundation Web*"}
$svc.Status = "Online"
$svc.Update()

In order to get virtual directories back run this PowerShell command
$wa = Get-SPWebApplication http://webAppUrl

$wa.ProvisionGlobally()

Disable Throttling for a single list


In situation where you need to disable throttle limit but you don’t want to disable for the whole web application as it will certainly cause performance issues, you can use the commands mentioned below to disable throttling for one lists only. Limit mentioned in the Central Administration will be applicable for all the other lists.
Example Scenario: if you are using InfoPath form with 2 fields (controls) on it and want field B to auto populate based on the value in field A. value are coming from a list that has more than 5k items in it , you might run in to issues.
$Site  =  Get-SPWeb -Identity <SiteURL>
$List  =  $Site.Lists[“List Name”]
$List.EnableThrottling =  $false

$List.Update()

Event ID 8313: A failure was reported when trying to invoke a service application


Recently I came across this issue and in SharePoint 2013 farm and find too many entries for Event ID 8313. When used process explorer I find out too many permission issues for the SP Service accounts on files and registry keys as well.

Event Text
A failure was reported when trying to invoke a service application: EndpointFailure
Process Name: OWSTIMER
Process ID: 2604
AppDomain Name: DefaultDomain
AppDomain ID: 1
Service Application Uri: urn:schemas-microsoft-com:sharepoint:service:e83f1cd236394b70beb0998888addcbc#authority=urn:uuid:8bca10c5c19a429289a7eea7f5159e86&authority=https://ServerName:32844/Topology/topology.svc
Active Endpoints: 2
Failed Endpoints: 1
Affected Endpoint:http://Serevrname:32843/e83f1cd236fgfgfgfbeb0998888addcbc/Metadatawebservice.svc
Source SharePoint Foundation
Event ID 8313
Level Error
User : spfarm

Solution: When used process explorer I find out too many permission issues for the SP Service accounts on files and registry keys as well. Also notice that Managed Meta Data service was running on the server it’s not supposed to. I stopped the service as it is running on another app server and run the following command to resolve permissions issue.
PSCONFIG.exe –cmd Secureresources
 Another power shell command for the same purpose is
Initialize-SPResourceSecurity to enforces security for all resources, including files, folders, and registry keys on Local Server.

What is Web Application , Application Pool and Site Collection in SharePoint.


In this article I try to explain difference between web application, application pool & site collections etc. Pretty basic topic but might help someone out there to understand the difference and how each object connects with other and what it does in term of functionality and connections with each other.
I will use an example and your opinion can be lot different than this, if so, please feel free to leave a comment and I will update this accordingly to make concept easier to understand.
Let’s do some definitions first: I know we don’t like definitions but there are easy ones.
Application Pool:
An application Pool is IIS object that contains either one or multiple web applications in it. On a high level application pool reserves or releases memory for web applications (and every thin in that web application) to use and take it back when not in use. It does lot more than this like security & web app isolation but we will discuss about this some other time.
Web Application:
Web application is nothing but just an IIS site. Which, in SharePoint comes with on data base attach to it by default (you can have more than one data bases but for simplicity we will discuss this some other time). Think of web application as an empty container that has nothing inside i.e. No contents.
Site Collection:
From the name it seems like a collection of sites but it’s an object with in the web application. As mentioned earlier the web application is an IIS Site, but site collection is a SharePoint object and you will not see this in IIS, it resides in web application. You can have n number of Site collection in a web application. Usually site collections are our team sites, Project sites etc.
Sub site & Lists, libraries
Sub site is a complete “web site “but it lives with in site collection (and that’s why it is called site collection). There can be n number of sites with in a Site Collection and each site can have a multiple lists and libraries where we store contents
Example:
Let’s take an example of an under construction house. All we have is boundary of the house and full basement, so if you go in to house it’s empty, nothing in there and basement is there. This is a web application that has one data base ( basement ) and its empty, address of this house is http://SPHouse and you can see this address in IIS as well.
Let’s build one room in this empty house and few closets and drawers with in this room. This room is our site collection and closets and drawers will be lists and libraries. You can have several rooms in this empty house and this way you will end up many site collections.
In each room you can have several small rooms let’s call them sub sites, these sub sites will always be in that site collection.
Now in technical terms you have one web application that deals with authentication and IIS routing, NLB and much more and within that one web application you can have N number of site collections (rooms), By default each site collection use the same Database that comes with the web application ( our basement) to store all the contents but we use list an libraries with in those site collections to store and manage contents in that data base( let’s say we forgot to build stairs to go in to basement)
Some URL examples (addresses)
·         If web application ( home) is http://SPHome à aka IIS Site
·         Each site collection ( room) can be http://SPhome/Sites/Room1 &http://SPHome/Sites/Room2
·         and list/libraries ( closets in room) can behttp://SPHome/Sites/Room1/Closet1/allitems.aspx &http://SPHome/Sites/Room2/Closet2/allitems.aspx

This is a very basic overview of each object. But with the new version of SharePoint ( 2013 ) there are several options for HNSC and managed path that allow to configure URLs of end user choice like vanity URLs or dedicated url for each site collections i.e. not dependent on web app url and much more . But I will cover this at some other time as I want to keep it basic for now.

Restore-SpSite : The operation that you are attempting to perform cannot be completed successfully

Recently I was asked to move a site collection from one farm to the other. No problem, piece of cake, right?
That what I thought and ran the command
SPSite-Restore …..After backing up. I have 20 site collection in the data base already and limit is set to 2000 but got this error
 Restore-SpSite : The operation that you are attempting to perform cannot be completed successfully. No content databases in the web application were available to store your site collection. The existing content databases may have reached the maximum number of site collections, or be set to read-only, or be offline, or may already contain a copy of this site collection. Create another content database for the Web application and then try the operation again 


Woo, I will never create a new data base for this, here is how I resolved this. Run the same command with additional parameters of “ Database name” & “Database Server”
E.g. Restore-SpSite URLGoesHere –Path **.bak -force –DatabaseServer ** -DatabaseName **
And it worked this time. Site was successfully restored.
In some cases if you are trying to restore or create a new site with the same url that was deleted some time ago, there are possibilities it has not been removed from the database permanently in that case try this.
Get-SPDeletedSite:

If the site exist with the same URL remove using
Remove-SPDletedSite –Identity
As shown in the image above. Once removed this site will be removed from database for ever permanently.

Tuesday 28 April 2015

Update Managed Metadata Term Store Admin using PowerShell


Scenario: After I restore managed metadata service application database from a different environment I was able to successfully attach it with my existing MMS Application and all the terms came up fine. Two other site collection also came from same environment and attached terms were displaying fine on sites as well after restore.
Issue: I notice I was not able to create new terms (drop down in term set & groups was not visible) even after changing the MMS administrator from Central Administration several times it was not working as expected . Reboot and IIS Reset did not work.
Resolution: I use Power-Shell script to change MMS administrator. Below is script that will allow you to do same and few other things.
$TaxonomySite = Get-SPSite http://Yoursiteurl
$TaxonomySession = Get-SPTaxonomySession -site $TaxonomySite
$TermStore = $TaxonomySession.TermStores[0]
Note: At this point you can run TaxonomySession.TermStores[0] and it will show you ID of your managed metadata service application and also show you the Groups name so you can check if you have selected the right URL on the first line. In my case I was using global term set and it was shared with 2 other site collections, so I believe any Site URL will work in the first command

To add new term store administrator run this command and it will automatically remove the existing one.
$TermStore.TermStoreAdministrators
$TermStore.AddTermStoreAdministrator(“i:0#.w|Domain\NewAdministrator”)
$TermStore.CommitAll()
 To check the administrator name you can sue this command:
$TermStore.TermStoreAdministrators.