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