本文共 1557 字,大约阅读时间需要 5 分钟。
在使用SharePoint文档库时,某些场景可能会导致文件默认进入“编辑前签出”状态。这种情况尤其会影响批量导入文件的工作流程,手动处理效率极低。本文将介绍一种使用PowerShell批量签入文档库中的文件的解决方案。
当文档库启用了“编辑前签出”功能时,批量导入文件时,默认会将所有文件设置为“编辑前签出”状态。这种情况会导致后续的文件管理工作变得异常麻烦。为了避免这一问题,我们可以利用PowerShell编写脚本,自动完成批量签入操作。
以下是实现批量签入的PowerShell脚本示例:
Add-PSSnapin Microsoft.SharePoint.PowerShellfunction CheckInDocument([string]$url) { $spWeb = Get-SPWeb $url $spDocument = $spWeb.Lists.TryGetList("Documents") Write-Host "需要签入文件的文档库: $($spDocument.Title)" $files = $spDocument.CheckedOutFiles Write-Host "需要签入的文件个数: $($files.Count)" $files | where { $_.CheckOutStatus -ne "None" } | % { $_.TakeOverCheckOut() $docItem = $spDocument.GetItemById($_.ListItemId) $docItem.File.CheckIn("Administrator Check In") Write-Host "$($docItem.File.Name) Check In" -ForegroundColor Green } $spWeb.Dispose()}CheckInDocument("http://reus") ####脚本功能说明
CheckInDocument的函数,接收文档库的URL参数。Get-SPWeb获取 SharePoint 网站,TryGetList("Documents")获取“文档”列表。TakeOverCheckOut,获取签入权限,随后通过CheckIn方法将文件签入文档库。.ps1文件。CheckInDocument函数:.\CheckInDocument.ps1 "http://[YourSite]"
这种方法能够显著提升文件管理效率,适用于需要频繁批量签入文件的场景。
转载地址:http://blxfk.baihongyu.com/