PowerShell: SharePoint Check In All Files
In SharePoint Site Document Library for check in all files or documents using PowerShell:
cls
Remove-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue
Add-PSSnapin Microsoft.SharePoint.Powershell
function CheckInDocument([string]$url)
{
$spWeb = Get-SPWeb $url
$SPBaseTypeDocumentLibrary = [Microsoft.SharePoint.SPBaseType]::DocumentLibrary
$lists = $spWeb.GetListsOfType($SPBaseTypeDocumentLibrary);
foreach ($list in $lists)
{
if ($list.Hidden -eq $False -and $list.BaseTemplate.ToString() -eq "1302")
{
Write-Host Checking in documents from Library : $list.Title
$getFolder = $spWeb.GetFolder($list.Title)
$files = $list.CheckedOutFiles
write-host "Total Checked Out Files : " $files.Count
$list.CheckedOutFiles | Where { $_.CheckOutStatus -ne "None" } |
ForEach {
$_.TakeOverCheckOut();
$docItem = $list.GetItemById($_.ListItemId);
$docItem.File.CheckIn("Checked In By Administrator");
Write-Host "$($docItem.File.Name) Checked In" -ForeGroundColor Green
}
}
}
$spWeb.Dispose()
}
CheckInDocument http://spdev-na2-01d:1800/sites/Contracts
cls
Remove-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue
Add-PSSnapin Microsoft.SharePoint.Powershell
function CheckInDocument([string]$url)
{
$spWeb = Get-SPWeb $url
$SPBaseTypeDocumentLibrary = [Microsoft.SharePoint.SPBaseType]::DocumentLibrary
$lists = $spWeb.GetListsOfType($SPBaseTypeDocumentLibrary);
foreach ($list in $lists)
{
if ($list.Hidden -eq $False -and $list.BaseTemplate.ToString() -eq "1302")
{
Write-Host Checking in documents from Library : $list.Title
$getFolder = $spWeb.GetFolder($list.Title)
$files = $list.CheckedOutFiles
write-host "Total Checked Out Files : " $files.Count
$list.CheckedOutFiles | Where { $_.CheckOutStatus -ne "None" } |
ForEach {
$_.TakeOverCheckOut();
$docItem = $list.GetItemById($_.ListItemId);
$docItem.File.CheckIn("Checked In By Administrator");
Write-Host "$($docItem.File.Name) Checked In" -ForeGroundColor Green
}
}
}
$spWeb.Dispose()
}
CheckInDocument http://spdev-na2-01d:1800/sites/Contracts
Comments
Post a Comment