SharePoint Admin

SharePoint error from the ULS logs

What is a Correlation ID in SharePoint?

In SharePoint 2010, you get a Correlation ID (which is a GUID) attached to your logs/error messages when something happens. This ID can then be used to lookup that specific error from the logs.

This Correlation ID is used per request-session in SharePoint 2010, and if you are in the process of requesting some information from SharePoint and bump into some problems along the way – your Correlation ID will be the best starting point for searching for what went wrong along that request!

Get Correlation ID of the error:

  • Copy the Correlation ID from the error message
  • Run SharePoint 2010 Management Shell
  •  Run the following command with your Correlation ID

Get-splogevent | ?{$_.Correlation -eq “CORRELATION ID”} | select Area, Category, Level, EventID, Message |Format-List

Or

Merge-SPLogFile -Path “.\error.log” -Correlation “CORRELATION ID

This cmdlet looks for logs within past 20 Minutes of time span.

Merge-SPLogFile -Path D:\errorLog.txt -StartTime “20/10/2017” -overwrite

or

$StartTime = (Get-Date).AddMinutes(-15)
Merge-SPLogFile -Path D:\Logs\FarmMergedLog.log -Overwrite -StartTime $StartTime

Ref :https://zimmergren.net/sp-2010-find-error-messages-with-a-correlation-id-token-in-sharepoint-2010/

_____________________________________________________________________________________

Clearing SharePoint configuration cache using PowerShell:

Have you come across an error: An update conflict has occurred, and you must re-try this action
I'm sure you did, as there is no way any SharePoint Admin would be spared with this error. 
This errors may come up in the following scenarios:
  • You are performing SharePoint Patching and while running the upgrade command via PowerShell you are presented with this error
  • You are trying to run some PowerShell script and this error pops-up
Clearing SharePoint Configuration Cache will help in the following scenarios:
  • To fix SharePoint Upgrade and Patching issues
  • SharePoint Timer Jobs stuck or running slow
  • Nintex Workflows or any Workflows failing to work intermittently and more..

Clearing SharePoint Configuration Cache is one of the safe things to try while troubleshooting, and sometimes even the most unexpected, unforgiving errors maybe resolved by quickly performing SharePoint Cache Configuration clearing. Thereby this is one of things to try when you are working on a long running issue

The guide to clear the SharePoint Configuration Cache is well documented here –

https://support.microsoft.com/en-us/help/939308/error-message-when-you-try-to-modify-or-to-delete-an-alternate-access

I always hated doing this way, especially if you are working on a Multi-Server SharePoint Farm as there are too many manual steps

Upon researching online to find a suitable PowerShell script, I found this well written script and I have used this script a few hundred times and works perfectly

https://mickeyjervin.wordpress.com/category/powershell/

There are few things you should note though..

Always remember to take backups of the Config folder. I have seen cases where the config cache refuses to rebuild from the SharePoint Configuration Database, and if you have no good backups, then you are in deep sh**

Which folder should we backup: “Drive:\ProgramData\Microsoft\SharePoint\Config\GUID” the GUID folder

Backing this GUID folder in any one of the Servers is good enough, and in worst case scenarios you can use the same backup and put it on every SharePoint Server in the Farm

I customized the above PowerShell so that it can automatically do the Backups for me 
and then clear the SharePoint Configuration Cache

The attached script at the bottom of this article, will work for SharePoint 2013 only

To get this working on a SharePoint 2010 Farm, open the file in Notepad++ , go to Line-24, update:

From:

Set-Variable timerServiceName -option Constant -value “SharePoint Timer Service“

To:

Set-Variable timerServiceName -option Constant -value “SharePoint 2010 Timer“

Save the file and now the exact same file can be run on SharePoint 2010 Farms

Prepare the Server, Trust me this is worth the Time and a one-time effort

I usually choose Central Admin Server and create the following folders & files:

  1. Choose a Drive on which you want place the backups and the Script. Choose other than Primary C:\Drive. In this I’m choosing D:\Drive
  2. Create a Folder called ‘ConfigCache’
  3. Inside ‘ConfigCache’ folder, create a folder called ‘Backups’, this is config folder backups will be stored
  4. Create a bat file called TimerCacheCode.bat

How to create a bat file? Create a blank notepad file and rename the .txt to .bat

  1. Open the TimerCacheCode.bat in notepad and add the following code:
%~d0

cd “%~dp0”

Powershell.exe .\2013ConfigCache.ps1

Pause

  1. Place the attached 2013ConfigCache.ps1 script inside ‘ConfigCache’ folder
  2. Your folder structure should now look like shown below:

  1. Open the 2013ConfigCache.ps1 script file using Notepad++, update the following lines:
    • Line 207: Update the folder path: D:\ConfigCache\Backups, depending on where which Drive was chosen to create the Folders
    • Line 210: Update the folder path: D:\ConfigCache\Backups, depending on where which Drive was chosen to create the Folders
    • Line 212: In this script, it is assumed that the Config folder is in the default location which is: C:\ProgramData\Microsoft\SharePoint\Config, update accordingly
  1. Once this is ready, whenever you want to clear the SharePoint Configuration Cache, just go to the TimerCacheCode.bat and Run as Administrator

  1. The output will look as follows:

The PowerShell script and the bat file is attached here. Rename the PowerShell script to .ps1 and the bat file to .bat

2013ConfigCache.ps1  TimerCacheCode

TimerCacheCode:

%~d0
cd “%~dp0”
Powershell.exe .\2013ConfigCache.ps1
Pause

2013ConfigCache.ps1

# Clear the SharePoint Timer Cache
#
# 2009 Mickey Kamp Parbst Jervin (mickeyjervin.wordpress.com)
# 2017 Adapted by Syed Abdul Khader (thesharegear.com) to work with SharePoint 2010, SharePoint 2013
# display more progress information, takes Backups of the GUID folder, restart all timer services in the farm,
# and make reusable functions.

# Output program information
Write-Host -foregroundcolor White “”
Write-Host -foregroundcolor White “Clear SharePoint Timer Cache”

#**************************************************************************************
# References
#**************************************************************************************
[void][reflection.assembly]::LoadWithPartialName(“Microsoft.SharePoint”)
[void][reflection.assembly]::LoadWithPartialName(“Microsoft.SharePoint.Administration”)
[void][reflection.assembly]::LoadWithPartialName(“System”)
[void][reflection.assembly]::LoadWithPartialName(“System.Collections”)
#**************************************************************************************

#**************************************************************************************
# Constants
#**************************************************************************************
Set-Variable timerServiceName -option Constant -value “SharePoint Timer Service”
Set-Variable timerServiceInstanceName -option Constant -value “Microsoft SharePoint Foundation Timer”

#**************************************************************************************
# Functions
#**************************************************************************************

#<summary>
# Stops the SharePoint Timer Service on each server in the SharePoint Farm.
#</summary>
#<param name=”$farm”>The SharePoint farm object.</param>
function StopSharePointTimerServicesInFarm([Microsoft.SharePoint.Administration.SPFarm]$farm)
{
Write-Host “”

# Iterate through each server in the farm, and each service in each server
foreach($server in $farm.Servers)
{
foreach($instance in $server.ServiceInstances)
{
# If the server has the timer service then stop the service
if($instance.TypeName -eq $timerServiceInstanceName)
{
[string]$serverName = $server.Name

Write-Host -foregroundcolor DarkGray -NoNewline “Stop ‘$timerServiceName’ service on server: “
Write-Host -foregroundcolor Gray $serverName

$service = Get-WmiObject -ComputerName $serverName Win32_Service -Filter “DisplayName=’$timerServiceName'”
$serviceInternalName = $service.Name
sc.exe \\$serverName stop $serviceInternalName > $null

# Wait until this service has actually stopped
WaitForServiceState $serverName $timerServiceName “Stopped”

break;
}
}
}

Write-Host “”
}

#<summary>
# Waits for the service on the server to reach the required service state.
# This can be used to wait for the “SharePoint 2010 Timer” service to stop or to start
#</summary>
#<param name=”$serverName”>The name of the server with the service to monitor.</param>
#<param name=”$serviceName”>The name of the service to monitor.</param>
#<param name=”$serviceState”>The service state to wait for, e.g. Stopped, or Running.</param>
function WaitForServiceState([string]$serverName, [string]$serviceName, [string]$serviceState)
{
Write-Host -foregroundcolor DarkGray -NoNewLine “Waiting for service ‘$serviceName’ to change state to $serviceState on server $serverName”

do
{
Start-Sleep 1
Write-Host -foregroundcolor DarkGray -NoNewLine “.”
$service = Get-WmiObject -ComputerName $serverName Win32_Service -Filter “DisplayName=’$serviceName'”
}
while ($service.State -ne $serviceState)

Write-Host -foregroundcolor DarkGray -NoNewLine ” Service is “
Write-Host -foregroundcolor Gray $serviceState
}

#<summary>
# Starts the SharePoint Timer Service on each server in the SharePoint Farm.
#</summary>
#<param name=”$farm”>The SharePoint farm object.</param>
function StartSharePointTimerServicesInFarm([Microsoft.SharePoint.Administration.SPFarm]$farm)
{
Write-Host “”

# Iterate through each server in the farm, and each service in each server
foreach($server in $farm.Servers)
{
foreach($instance in $server.ServiceInstances)
{
# If the server has the timer service then start the service
if($instance.TypeName -eq $timerServiceInstanceName)
{
[string]$serverName = $server.Name

Write-Host -foregroundcolor DarkGray -NoNewline “Start ‘$timerServiceName’ service on server: “
Write-Host -foregroundcolor Gray $serverName

$service = Get-WmiObject -ComputerName $serverName Win32_Service -Filter “DisplayName=’$timerServiceName'”
[string]$serviceInternalName = $service.Name
sc.exe \\$serverName start $serviceInternalName > $null

WaitForServiceState $serverName $timerServiceName “Running”

break;
}
}
}

Write-Host “”
}

#<summary>
# Removes all xml files recursive on an UNC path
#</summary>
#<param name=”$farm”>The SharePoint farm object.</param>
function DeleteXmlFilesFromConfigCache([Microsoft.SharePoint.Administration.SPFarm]$farm)
{
Write-Host “”
Write-Host -foregroundcolor DarkGray “Delete xml files”

[string] $path = “”

# Iterate through each server in the farm, and each service in each server
foreach($server in $farm.Servers)
{
foreach($instance in $server.ServiceInstances)
{
# If the server has the timer service delete the XML files from the config cache
if($instance.TypeName -eq $timerServiceInstanceName)
{
[string]$serverName = $server.Name

Write-Host -foregroundcolor DarkGray -NoNewline “Deleting xml files from config cache on server: “
Write-Host -foregroundcolor Gray $serverName

# Remove all xml files recursive on an UNC path
$path = “\\” + $serverName + “\c$\ProgramData\Microsoft\SharePoint\Config\*-*\*.xml”
Remove-Item -path $path -Force

break
}
}
}

Write-Host “”
}

#<summary>
# Clears the SharePoint cache on an UNC path
#</summary>
#<param name=”$farm”>The SharePoint farm object.</param>
function ClearTimerCache([Microsoft.SharePoint.Administration.SPFarm]$farm)
{
Write-Host “”
Write-Host -foregroundcolor DarkGray “Clear the cache”

[string] $path = “”

# Iterate through each server in the farm, and each service in each server
foreach($server in $farm.Servers)
{
foreach($instance in $server.ServiceInstances)
{
# If the server has the timer service then force the cache settings to be refreshed
if($instance.TypeName -eq $timerServiceInstanceName)
{
[string]$serverName = $server.Name

Write-Host -foregroundcolor DarkGray -NoNewline “Clearing timer cache on server: “
Write-Host -foregroundcolor Gray $serverName

# Clear the cache on an UNC path
# 1 = refresh all cache settings
$path = “\\” + $serverName + “\c$\ProgramData\Microsoft\SharePoint\Config\*-*\cache.ini”
Set-Content -path $path -Value “1”

break
}
}
}

Write-Host “”
}

#**************************************************************************************
# Main script block
#**************************************************************************************

# Get the local farm instance
[Microsoft.SharePoint.Administration.SPFarm]$farm = [Microsoft.SharePoint.Administration.SPFarm]::get_Local()

#Take Backup of Config Folder
Write-Host “Deleting the previous backup of the Config folder to save some space” -foregroundcolor “yellow”
Remove-Item “D:\ConfigCache\Backups\*” -recurse -force
Write-Host “Previous Backup folder deleted” -foregroundcolor “yellow”
$LogTime = Get-Date -Format yyyy-MM-dd
$dirName = New-Item “D:\ConfigCache\Backups\$Logtime” -ItemType directory -force
Write-Host “Taking Backup of Config Folder” -foregroundcolor “yellow”
Copy-Item “C:\ProgramData\Microsoft\SharePoint\Config\*-*” $dirName -recurse -force
Write-Host “Backup done” -foregroundcolor “Yellow”

# Stop the SharePoint Timer Service on each server in the farm
StopSharePointTimerServicesInFarm $farm

# Delete all xml files from cache config folder on each server in the farm
DeleteXmlFilesFromConfigCache $farm

# Clear the timer cache on each server in the farm
ClearTimerCache $farm

# Start the SharePoint Timer Service on each server in the farm
StartSharePointTimerServicesInFarm $farm

Ref : http://thesharegear.com

 

Advertisements