文件被簽出後對其他用戶隱藏,導致文件統計數量不準。需掃描整個 Site Collection 找出所有簽出文件並匯出報表。
Add-PSSnapin Microsoft.SharePoint.PowerShell
function GetAllCheckOutFiles([string]$siteUrl)
{
$spSite = Get-SPSite $siteUrl
$spSite.AllWebs | ForEach-Object {
$_.Lists | Where-Object { $_.BaseTemplate -eq "DocumentLibrary" -and $_.Hidden -eq $false } | ForEach-Object {
# 輸出:文件 URL、簽出者
$_.CheckedOutFiles | Select-Object @{Name="Url";Expression={$_.Url}}, @{Name="CheckedOutBy";Expression={$_.CheckedOutByName}} |
Out-File "c:\txtResult.txt" -Append
}
}
$spSite.Dispose()
}
# 執行
GetAllCheckOutFiles("https://your-sharepoint-site")
Get-SPSite 取得 Site Collection 物件。AllWebs 遍歷所有子網站。BaseTemplate -eq "DocumentLibrary" 過濾文件庫(排除隱藏清單)。CheckedOutFiles 集合包含所有被簽出的 SPCheckedOutFile 物件,屬性含 Url、CheckedOutByName、CheckedOutBy (SPUser)、TimeLastModified。c:\txtResult.txt,可進一步匯入 Excel 分析。Web.Url、List.Title 欄位便於定位文件所在庫。Export-Csv -Path "c:\CheckoutReport.csv" -NoTypeInformation。Where-Object { $_.Title -notmatch "Assets" }。Write-Host。