Introduction

Many of you must have come across the issue “An update conflict has occurred and you must re-try this action” and it is suggested to remove the file system cache on the front-end servers. There are many articles to show how to do this manually. But here I will show you how to resolve it using a PowerShell script.

Cause for this issue

This issue occurs if the contents of the file system cache on the front-end servers are newer than the contents of the configuration database.

Resolution

To resolve this issue, clear the file system cache on all servers in the server Farm on which the Windows SharePoint Services Timer service is running. This can be done manually, but consider a large Farm where the administrator needs to login to each of the servers to perform the activity manually. It is time-consuming and people can make mistakes. PowerShell becomes handy here.

The following procedure can resolve the issue:

  1. Stop the SharePoint timer service
  2. Take a backup of the system cache files before deleting it
  3. Delete the XML files from the cache folder
  4. Reset the cache.ini file to the value 1
  5. Start the SharePoint timer service

Now I will explain how to perform the preceding tasks using a PowerShell script.

Stop SharePoint timer service

The following piece of code stops the SharePoint timer service:

  1. Function StopSPTimerServicesInFarm([Microsoft.SharePoint.Administration.SPFarm]$farm)
  2. {
  3. Write-Host ""
  4. foreach($server in $farm.Servers)
  5. {
  6. foreach($instance in $server.ServiceInstances)
  7. {
  8. # If the server has the timer service then stop the service
  9. if($instance.TypeName -eq $timerServiceInstanceName)
  10. {
  11. [string]$serverName = $server.Name
  12. Write-Host "Stop " $timerServiceName " service on server: " $serverName -fore yellow
  13. $service = Get-WmiObject -ComputerName $serverName Win32_Service -Filter "DisplayName='$timerServiceName'"
  14. $serviceInternalName = $service.Name
  15. sc.exe \\$serverName stop $serviceInternalName > $null
  16. # Wait until this service has actually stopped
  17. write-host "Waiting for '$timerServiceName' service on server: " $serverName " to be stopped" -fore yellow
  18. do
  19. {
  20. Start-Sleep 1
  21. Write-Host -foregroundcolor DarkGray -NoNewLine "."
  22. $service = Get-WmiObject -ComputerName $serverName Win32_Service -Filter "DisplayName='$timerServiceName'"
  23. }
  24. while ($service.State -ne "Stopped")
  25. write-host " '$timerServiceName' service on server: " $serverName " stopped successfully" -fore green
  26. break;
  27. }
  28. }
  29. }
  30. Write-Host ""
  31. }
Backup config cache files

The following piece of code backs up the config cache files before deleting it:
  1. Function BackupSPConfigFiles([Microsoft.SharePoint.Administration.SPFarm]$farm)
  2. {
  3. write-host ""
  4. write-host "Backup SP config cache files" -fore yellow
  5. foreach($server in $farm.servers)
  6. {
  7. foreach($instance in $server.ServiceInstances)
  8. {
  9. if($instance.TypeName -eq $timerServiceInstanceName)
  10. {
  11. $ServerName = $server.name
  12. $FolderName = $servername + "SPConfigCacheBackup"
  13. write-host "Creating a folder to hold the backup files" -fore magenta
  14. write-host "Checking whether the folder aleady exist"
  15. if(Test-path $scriptbase\$FolderName)
  16. {
  17. write-host "Folder already exists and the script is deleting it......"
  18. remove-item $scriptbase\$FolderName -recurse -confirm:$false
  19. write-host "Existing folder deleted" -fore green
  20. }
  21. else
  22. {
  23. write-host "Folder does not exist"
  24. }
  25. New-Item $scriptbase\$FolderName -type directory
  26. write-host "New folder created to hold the backup files" -fore magenta
  27. write-host "Backup of SP config files for the server " $serverName " started ...... " -fore yellow
  28. $path = "\\" + $serverName + "\c$\ProgramData\Microsoft\SharePoint\Config"
  29. Copy-Item $path -Destination $scriptbase\$FolderName -recurse
  30. write-host "SP config cache files backed up for the server " $serverName " Sucessfully..." -fore green
  31. }
  32. }
  33. }
  34. write-host "SP config caches files are backed up" -fore green
  35. write-host ""
  36. }
Deleting XML files

The following piece of code deletes the XML files:
  1. Function DeletingXMLFiles([Microsoft.SharePoint.Administration.SPFarm]$farm)
  2. {
  3. Write-host ""
  4. write-host "Deleting SP config cache XML files from each server in the farm" -fore yellow
  5. $path = ""
  6. foreach($server in $farm.servers)
  7. {
  8. foreach($instance in $server.ServiceInstances)
  9. {
  10. if($instance.TypeName -eq $timerServiceInstanceName)
  11. {
  12. $serverName = $server.Name
  13. write-host "Deleting SP config cache files from the server " $servername -fore magenta
  14. $path = "\\" + $serverName + "\c$\ProgramData\Microsoft\SharePoint\Config\*-*\*.xml"
  15. remove-item -path $path -force
  16. write-host "SP config cache files deleted on the server " $servername -fore magenta
  17. break
  18. }
  19. }
  20. }
  21. write-host "SP config cache XML files from each server in the farm is deleted successfully......" -fore green
  22. write-host ""
  23. }
Reset timer cache

The following piece of code resets the timer cache:
  1. Function ResetTimerCache([Microsoft.SharePoint.Administration.SPFarm]$farm)
  2. {
  3. write-host ""
  4. write-host "Reseting the value of timer cache to 1" -fore yellow
  5. $path = ""
  6. foreach($server in $farm.servers)
  7. {
  8. foreach($instance in $server.ServiceInstances)
  9. {
  10. if($instance.TypeName -eq $timerServiceInstanceName)
  11. {
  12. $serverName = $server.Name
  13. write-host "Reseting the value of timer cache file in server " $serverName -fore magenta
  14. $path = "\\" + $serverName + "\c$\ProgramData\Microsoft\SharePoint\Config\*-*\cache.ini"
  15. Set-Content -path $path -Value "1"
  16. write-host "Value of timer cache file in server " $serverName " is resetted to 1" -fore magenta
  17. break
  18. }
  19. }
  20. }
  21. write-host "The value of timer cache is resetted to 1 in all the SP servers in the farm" -fore green
  22. write-host ""
  23. }
Start SharePoint timer service
  1. Function StartSPTimerServicesInFarm([Microsoft.SharePoint.Administration.SPFarm]$farm)
  2. {
  3. Write-Host ""
  4. foreach($server in $farm.Servers)
  5. {
  6. foreach($instance in $server.ServiceInstances)
  7. {
  8. # If the server has the timer service then stop the service
  9. if($instance.TypeName -eq $timerServiceInstanceName)
  10. {
  11. [string]$serverName = $server.Name
  12. Write-Host "Start " $timerServiceName " service on server: " $serverName -fore yellow
  13. $service = Get-WmiObject -ComputerName $serverName Win32_Service -Filter "DisplayName='$timerServiceName'"
  14. $serviceInternalName = $service.Name
  15. sc.exe \\$serverName start $serviceInternalName > $null
  16. # Wait until this service starts running
  17. write-host "Waiting for " $timerServiceName " service on server: " $serverName " to be started" -fore yellow
  18. do
  19. {
  20. Start-Sleep 1
  21. Write-Host -foregroundcolor DarkGray -NoNewLine "."
  22. $service = Get-WmiObject -ComputerName $serverName Win32_Service -Filter "DisplayName='$timerServiceName'"
  23. }
  24. while ($service.State -ne "Running")
  25. write-host $timerServiceName " service on server: " $serverName " started successfully" -fore green
  26. break;
  27. }
  28. }
  29. }
  30. Write-Host ""
  31. }
Complete Code
  1. $LogTime = Get-Date -Format yyyy-MM-dd_hh-mm
  2. $LogFile = ".\ClearSPConfigCachePatch-$LogTime.rtf"
  3. # Add SharePoint PowerShell Snapin
  4. if ( (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null ) {
  5. Add-PSSnapin Microsoft.SharePoint.Powershell
  6. }
  7. $scriptBase = split-path $SCRIPT:MyInvocation.MyCommand.Path -parent
  8. Set-Location $scriptBase
  9. #Deleting any .rtf files in the scriptbase location
  10. $FindRTFFile = Get-ChildItem $scriptBase\*.* -include *.rtf
  11. if($FindRTFFile)
  12. {
  13. foreach($file in $FindRTFFile)
  14. {
  15. remove-item $file
  16. }
  17. }
  18. start-transcript $logfile
  19. Write-host "##############Following steps will be involved################" -fore green
  20. write-host "Step 1 - Stop the timerservice" -fore cyan
  21. write-host "Step 2 - Take the backup of config cache file" -fore cyan
  22. write-host "Step 3 - Delete the XML files" -fore cyan
  23. write-host "Step 4 - Reset the cache.ini file" -fore cyan
  24. write-host "Step 5 - Start the SP timerservice" -fore cyan
  25. Write-host "##############Above steps will be involved##################" -fore green
  26. $global:timerServiceName = "SharePoint 2010 Timer"
  27. $global:timerServiceInstanceName = "Microsoft SharePoint Foundation Timer"
  28. # Get the local farm instance
  29. [Microsoft.SharePoint.Administration.SPFarm]$farm = [Microsoft.SharePoint.Administration.SPFarm]::get_Local()
  30. Function StopSPTimerServicesInFarm([Microsoft.SharePoint.Administration.SPFarm]$farm)
  31. {
  32. Write-Host ""
  33. foreach($server in $farm.Servers)
  34. {
  35. foreach($instance in $server.ServiceInstances)
  36. {
  37. # If the server has the timer service then stop the service
  38. if($instance.TypeName -eq $timerServiceInstanceName)
  39. {
  40. [string]$serverName = $server.Name
  41. Write-Host "Stop " $timerServiceName " service on server: " $serverName -fore yellow
  42. $service = Get-WmiObject -ComputerName $serverName Win32_Service -Filter "DisplayName='$timerServiceName'"
  43. $serviceInternalName = $service.Name
  44. sc.exe \\$serverName stop $serviceInternalName > $null
  45. # Wait until this service has actually stopped
  46. write-host "Waiting for '$timerServiceName' service on server: " $serverName " to be stopped" -fore yellow
  47. do
  48. {
  49. Start-Sleep 1
  50. Write-Host -foregroundcolor DarkGray -NoNewLine "."
  51. $service = Get-WmiObject -ComputerName $serverName Win32_Service -Filter "DisplayName='$timerServiceName'"
  52. }
  53. while ($service.State -ne "Stopped")
  54. write-host " '$timerServiceName' service on server: " $serverName " stopped successfully" -fore green
  55. break;
  56. }
  57. }
  58. }
  59. Write-Host ""
  60. }
  61. Function BackupSPConfigFiles([Microsoft.SharePoint.Administration.SPFarm]$farm)
  62. {
  63. write-host ""
  64. write-host "Backup SP config cache files" -fore yellow
  65. foreach($server in $farm.servers)
  66. {
  67. foreach($instance in $server.ServiceInstances)
  68. {
  69. if($instance.TypeName -eq $timerServiceInstanceName)
  70. {
  71. $ServerName = $server.name
  72. $FolderName = $servername + "SPConfigCacheBackup"
  73. write-host "Creating a folder to hold the backup files" -fore magenta
  74. write-host "Checking whether the folder aleady exist"
  75. if(Test-path $scriptbase\$FolderName)
  76. {
  77. write-host "Folder already exists and the script is deleting it......"
  78. remove-item $scriptbase\$FolderName -recurse -confirm:$false
  79. write-host "Existing folder deleted" -fore green
  80. }
  81. else
  82. {
  83. write-host "Folder does not exist"
  84. }
  85. New-Item $scriptbase\$FolderName -type directory
  86. write-host "New folder created to hold the backup files" -fore magenta
  87. write-host "Backup of SP config files for the server " $serverName " started ...... " -fore yellow
  88. $path = "\\" + $serverName + "\c$\ProgramData\Microsoft\SharePoint\Config"
  89. Copy-Item $path -Destination $scriptbase\$FolderName -recurse
  90. write-host "SP config cache files backed up for the server " $serverName " Sucessfully..." -fore green
  91. }
  92. }
  93. }
  94. write-host "SP config caches files are backed up" -fore green
  95. write-host ""
  96. }
  97. Function DeletingXMLFiles([Microsoft.SharePoint.Administration.SPFarm]$farm)
  98. {
  99. Write-host ""
  100. write-host "Deleting SP config cache XML files from each server in the farm" -fore yellow
  101. $path = ""
  102. foreach($server in $farm.servers)
  103. {
  104. foreach($instance in $server.ServiceInstances)
  105. {
  106. if($instance.TypeName -eq $timerServiceInstanceName)
  107. {
  108. $serverName = $server.Name
  109. write-host "Deleting SP config cache files from the server " $servername -fore magenta
  110. $path = "\\" + $serverName + "\c$\ProgramData\Microsoft\SharePoint\Config\*-*\*.xml"
  111. remove-item -path $path -force
  112. write-host "SP config cache files deleted on the server " $servername -fore magenta
  113. break
  114. }
  115. }
  116. }
  117. write-host "SP config cache XML files from each server in the farm is deleted successfully......" -fore green
  118. write-host ""
  119. }
  120. Function ResetTimerCache([Microsoft.SharePoint.Administration.SPFarm]$farm)
  121. {
  122. write-host ""
  123. write-host "Reseting the value of timer cache to 1" -fore yellow
  124. $path = ""
  125. foreach($server in $farm.servers)
  126. {
  127. foreach($instance in $server.ServiceInstances)
  128. {
  129. if($instance.TypeName -eq $timerServiceInstanceName)
  130. {
  131. $serverName = $server.Name
  132. write-host "Reseting the value of timer cache file in server " $serverName -fore magenta
  133. $path = "\\" + $serverName + "\c$\ProgramData\Microsoft\SharePoint\Config\*-*\cache.ini"
  134. Set-Content -path $path -Value "1"
  135. write-host "Value of timer cache file in server " $serverName " is resetted to 1" -fore magenta
  136. break
  137. }
  138. }
  139. }
  140. write-host "The value of timer cache is resetted to 1 in all the SP servers in the farm" -fore green
  141. write-host ""
  142. }
  143. Function StartSPTimerServicesInFarm([Microsoft.SharePoint.Administration.SPFarm]$farm)
  144. {
  145. Write-Host ""
  146. foreach($server in $farm.Servers)
  147. {
  148. foreach($instance in $server.ServiceInstances)
  149. {
  150. # If the server has the timer service then stop the service
  151. if($instance.TypeName -eq $timerServiceInstanceName)
  152. {
  153. [string]$serverName = $server.Name
  154. Write-Host "Start " $timerServiceName " service on server: " $serverName -fore yellow
  155. $service = Get-WmiObject -ComputerName $serverName Win32_Service -Filter "DisplayName='$timerServiceName'"
  156. $serviceInternalName = $service.Name
  157. sc.exe \\$serverName start $serviceInternalName > $null
  158. # Wait until this service starts running
  159. write-host "Waiting for " $timerServiceName " service on server: " $serverName " to be started" -fore yellow
  160. do
  161. {
  162. Start-Sleep 1
  163. Write-Host -foregroundcolor DarkGray -NoNewLine "."
  164. $service = Get-WmiObject -ComputerName $serverName Win32_Service -Filter "DisplayName='$timerServiceName'"
  165. }
  166. while ($service.State -ne "Running")
  167. write-host $timerServiceName " service on server: " $serverName " started successfully" -fore green
  168. break;
  169. }
  170. }
  171. }
  172. Write-Host ""
  173. }
  174. #############Calling functions################
  175. StopSPTimerServicesInFarm $farm
  176. BackupSPConfigFiles $farm
  177. DeletingXMLFiles $farm
  178. ResetTimerCache $farm
  179. StartSPTimerServicesInFarm $farm
  180. ##########################################
  181. write-host "SCRIPT COMPLETED" -fore cyan
  182. stop-transcript
Execution Procedure

Step 1: Download the script and copy it to the SharePoint server.

Step 2: Navigate to the script path.

Step 3: Execute the script.



Conclusion

Thus this article explained how to troubleshoot the “Update conflict” error in SharePoint using a PowerShell script.