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






Comments

Popular posts from this blog

C# Copy files from one server to another

Export SharePoint Online Group Users to Excel using Powershell

Suppress StyleCop SA1600