Check In documents with no checked in version using powershell

Published by Shubham Bansal on

When you upload a file in a SharePoint document library and “Require checked out” setting is enabled on the document library, you will have to check in the document at least once to make it available for others. you can take ownership of these documents by going to
Library settings -> Manage files which have no check in version
Select the documents and click Take ownership of the selection and then check in the documents.
Imagine you have to perform the same operation for hundreds of documents.
Here is a powershell script which can help you to check in all the documents all at once:
Add-PSSnapin *sh*
$WebUrl = Read-Host "Enter the URL of the SharePoint site"
$Library = Read-Host "Enter display name of the document library"
$UserDisplayName = Read-Host "Enter display name of the user"


$Web = Get-SPWeb $WebUrl 
$List = $web.Lists[$Library]
$CheckedOutFiles = $list.CheckedOutFiles

ForEach($File in $CheckedOutFiles )
{

If($File.CheckedOutBy.DisplayName -eq $UserDisplayName )
{
$File.LeafName
$File.TakeOverCheckOut()
#Check in
$List.GetItemById($File.ListItemId).File.Checkin("Checked in by Administrator")
}
}

 4,845 total views,  3 views today

Care to Share?

0 Comments

Leave a Reply