Today, We will learn about Clear SharePoint Config Cache files with powershell scripts. Now write the following code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
$LogTime = Get-Date -Format yyyy-MM-dd_hh-mm $LogFile = ".\ClearSPConfigCachePatch-$LogTime.rtf" # Add SharePoint PowerShell Snapin if ( (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null ) { Add-PSSnapin Microsoft.SharePoint.Powershell } $scriptBase = split-path $SCRIPT:MyInvocation.MyCommand.Path -parent Set-Location $scriptBase #Deleting any .rtf files in the scriptbase location $FindRTFFile = Get-ChildItem $scriptBase\*.* -include *.rtf if($FindRTFFile) { foreach($file in $FindRTFFile) { remove-item $file } } start-transcript $logfile Write-host "##############Following steps will be involved################" -fore green write-host "Step 1 - Stop the timerservice" -fore cyan write-host "Step 2 - Take the backup of config cache file" -fore cyan write-host "Step 3 - Delete the XML files" -fore cyan write-host "Step 4 - Reset the cache.ini file" -fore cyan write-host "Step 5 - Start the SP timerservice" -fore cyan Write-host "##############Above steps will be involved##################" -fore green $global:timerServiceName = "SharePoint 2010 Timer" $global:timerServiceInstanceName = "Microsoft SharePoint Foundation Timer" # Get the local farm instance [Microsoft.SharePoint.Administration.SPFarm]$farm = [Microsoft.SharePoint.Administration.SPFarm]::get_Local() Function StopSPTimerServicesInFarm([Microsoft.SharePoint.Administration.SPFarm]$farm) { Write-Host "" 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 "Stop " $timerServiceName " service on server: " $serverName -fore yellow $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 write-host "Waiting for '$timerServiceName' service on server: " $serverName " to be stopped" -fore yellow do { Start-Sleep 1 Write-Host -foregroundcolor DarkGray -NoNewLine "." $service = Get-WmiObject -ComputerName $serverName Win32_Service -Filter "DisplayName='$timerServiceName'" } while ($service.State -ne "Stopped") write-host " '$timerServiceName' service on server: " $serverName " stopped successfully" -fore green break; } } } Write-Host "" } Function BackupSPConfigFiles([Microsoft.SharePoint.Administration.SPFarm]$farm) { write-host "" write-host "Backup SP config cache files" -fore yellow foreach($server in $farm.servers) { foreach($instance in $server.ServiceInstances) { if($instance.TypeName -eq $timerServiceInstanceName) { $ServerName = $server.name $FolderName = $servername + "SPConfigCacheBackup" write-host "Creating a folder to hold the backup files" -fore magenta write-host "Checking whether the folder aleady exist" if(Test-path $scriptbase\$FolderName) { write-host "Folder already exists and the script is deleting it......" remove-item $scriptbase\$FolderName -recurse -confirm:$false write-host "Existing folder deleted" -fore green } else { write-host "Folder does not exist" } New-Item $scriptbase\$FolderName -type directory write-host "New folder created to hold the backup files" -fore magenta write-host "Backup of SP config files for the server " $serverName " started ...... " -fore yellow $path = "\\" + $serverName + "\c$\ProgramData\Microsoft\SharePoint\Config" Copy-Item $path -Destination $scriptbase\$FolderName -recurse write-host "SP config cache files backed up for the server " $serverName " Sucessfully..." -fore green } } } write-host "SP config caches files are backed up" -fore green write-host "" } Function DeletingXMLFiles([Microsoft.SharePoint.Administration.SPFarm]$farm) { Write-host "" write-host "Deleting SP config cache XML files from each server in the farm" -fore yellow $path = "" foreach($server in $farm.servers) { foreach($instance in $server.ServiceInstances) { if($instance.TypeName -eq $timerServiceInstanceName) { $serverName = $server.Name write-host "Deleting SP config cache files from the server " $servername -fore magenta $path = "\\" + $serverName + "\c$\ProgramData\Microsoft\SharePoint\Config\*-*\*.xml" remove-item -path $path -force write-host "SP config cache files deleted on the server " $servername -fore magenta break } } } write-host "SP config cache XML files from each server in the farm is deleted successfully......" -fore green write-host "" } Function ResetTimerCache([Microsoft.SharePoint.Administration.SPFarm]$farm) { write-host "" write-host "Reseting the value of timer cache to 1" -fore yellow $path = "" foreach($server in $farm.servers) { foreach($instance in $server.ServiceInstances) { if($instance.TypeName -eq $timerServiceInstanceName) { $serverName = $server.Name write-host "Reseting the value of timer cache file in server " $serverName -fore magenta $path = "\\" + $serverName + "\c$\ProgramData\Microsoft\SharePoint\Config\*-*\cache.ini" Set-Content -path $path -Value "1" write-host "Value of timer cache file in server " $serverName " is resetted to 1" -fore magenta break } } } write-host "The value of timer cache is resetted to 1 in all the SP servers in the farm" -fore green write-host "" } Function StartSPTimerServicesInFarm([Microsoft.SharePoint.Administration.SPFarm]$farm) { Write-Host "" 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 "Start " $timerServiceName " service on server: " $serverName -fore yellow $service = Get-WmiObject -ComputerName $serverName Win32_Service -Filter "DisplayName='$timerServiceName'" $serviceInternalName = $service.Name sc.exe \\$serverName start $serviceInternalName > $null # Wait until this service starts running write-host "Waiting for " $timerServiceName " service on server: " $serverName " to be started" -fore yellow do { Start-Sleep 1 Write-Host -foregroundcolor DarkGray -NoNewLine "." $service = Get-WmiObject -ComputerName $serverName Win32_Service -Filter "DisplayName='$timerServiceName'" } while ($service.State -ne "Running") write-host $timerServiceName " service on server: " $serverName " started successfully" -fore green break; } } } Write-Host "" } #############Calling functions################ StopSPTimerServicesInFarm $farm BackupSPConfigFiles $farm DeletingXMLFiles $farm ResetTimerCache $farm StartSPTimerServicesInFarm $farm ########################################## write-host "SCRIPT COMPLETED" -fore cyan stop-transcript |
Best SharePoint 2013 Hosting Recommendation
HostForLIFE.eu
HostForLIFE.eu offer the Best, Cheap and Recommended SharePoint 2013 hosting start from €9.99/month. They can load your site against anticipated traffic and recommend the best option for you. HostForLIFE.eu is Microsoft No #1 Recommended Windows and ASP.NET Hosting in European Continent. Their service is ranked the highest top #1 spot in several European countries, such as: Germany, Italy, Netherlands, France, Belgium, United Kingdom, Sweden, Finland, Switzerland and many top European countries.
ASPHostPortal.com
ASPHostPortal.com’s Best ASP.NET hosting platform on Windows 2012 and Windows 2008 is compatible with SharePoint 2013 hosting. Needless to say, you’ll be able to really feel very comfy with their hosting service. Their best and inexpensive SharePoint 2013 hosting package is starting from $9.99/mo only. And with their promo code, you will get free domain as well. Not just that, in addition they supply 30 days cash back guarantee. Their servers are 99.99% uptime, it’s important believe which you require for your SharePoint 2013 site, so your website is by no means down.
DiscountService.com.au
Get high functionality, best uptime along with the most dependable SharePoint 2013 Hosting site with them. SharePoint 2013 hosting from DiscountService.com.au provides a protected, trustworthy and performance-driven foundation for your website and apps. If you’re searching for the correct Windows ASP.NET hosting that support SharePoint 2013 hosting provider, they are the correct selection for you. They have proactive monitoring down to seconds with reactive options in spot to ensure the stability in the services they offer. All hosting servers are monitored 24/7/365. They use enterprise software to monitor their whole network infrastructure. Their very best and inexpensive SharePoint 2013 hosting price begins from $10.00 monthly.