当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 如何使用 PowerShell 清除 SharePoint 配置缓存?

作者:精品下载站 日期:2024-12-14 20:58:49 浏览:15 分类:玩电脑

如何使用 PowerShell 清除 SharePoint 配置缓存?


清除 SharePoint 配置缓存可以解决许多常见问题,例如“发生更新冲突,您必须重试此操作”。另一篇文章中解释了手动清除 SharePoint 2007 配置缓存:如何清除 SharePoint 配置缓存?这是清除SharePoint 2007/2010/2013配置缓存的PowerShell版本。


Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue

#Stop SharePoint 2013 Timer service
Stop-Service SPTimerV4

#Configuration Cache folder
$folders = Get-ChildItem C:\ProgramData\Microsoft\SharePoint\Config 

#Get the GUID folder where cache.ini lives.
foreach ($folder in $folders)
    {
    $items = Get-ChildItem $folder.FullName -Recurse
    foreach ($item in $items)
        {
            if ($item.Name.ToLower() -eq "cache.ini")
                {
                    $cachefolder = $folder.FullName
                }                
        }
    }
#Delete all XML Files
$cachefolderitems = Get-ChildItem $cachefolder -Recurse
    foreach ($cachefolderitem in $cachefolderitems)
        {
            if ($cachefolderitem -like "*.xml")
                {
                   $cachefolderitem.Delete()
                }        
        }
#Set "Cache.ini" file's content to 1        
$a = Get-Content  $cachefolder\cache.ini
$a  = 1
Set-Content $a -Path $cachefolder\cache.ini

#Start SharePoint Timer Service
start-Service SPTimerV4 

致谢:https://blogs.technet.com/b/sp/archive/2013/05/29/clear-sharepoint-config-cache-with-powershell.aspx

重置所有服务器上的 SharePoint 2013 配置缓存:

此操作在 SharePoint 场中的所有服务器上执行此操作:


Add-PSSnapin microsoft.sharepoint.powershell -ea SilentlyContinue

#Get all SharePoint Servers
$Servers = Get-SPServer | ? {$_.Role -ne "Invalid"} | Select -ExpandProperty Address

#Iterate through each server and reset SharePoint config cache
Invoke-Command -ComputerName $Servers -ScriptBlock {
try {
        Write-Host "$env:COMPUTERNAME - Stopping timer service"
        Stop-Service SPTimerV4

        #Get Config Cache Folder
        $ConfigDbId = [Guid](Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions.0\Secure\ConfigDB' -Name Id).Id #Path to the '15 hive' ConfigDB in the registry
        $CacheFolder = Join-Path -Path ([Environment]::GetFolderPath("CommonApplicationData")) -ChildPath "Microsoft\SharePoint\Config$ConfigDbId"

        Write-Host "$env:COMPUTERNAME - Clearing cache folder $CacheFolder"
        #Delete all XML Files
        Get-ChildItem "$CacheFolder\*" -Filter *.xml | Remove-Item

        Write-Host "$env:COMPUTERNAME - Resetting cache ini file"
        $CacheIni = Get-Item "$CacheFolder\Cache.ini"
        Set-Content -Path $CacheIni -Value "1"
    }
finally{
        Write-Host "$env:COMPUTERNAME - Starting timer service"
        Start-Service SPTimerV4
    }
}

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯