PowerShell to Manage Files Which Have No Checked in Version in SharePoint
Requirement:Â PowerShell to Manage files which have no checked in version in SharePoint.
How to Manage files which have no checked-in version in SharePoint 2016?
When a file is uploaded through explorer view or multiple file upload – without supplying mandatory column values or when you have “Require Check out” option set to “Yes”, then the file becomes “File with no checked-in version”!
These files with no check in version don’t appear for any other users, even to administrators – until the one who uploaded checks them in. As an administrator, you can take control over those files with the “Manage files which have no checked in version” link in the library settings.
How to take control of Files which have no checked in version?
The manage checked out files page gives you the list of all documents which are uploaded to the document library but never checked in. Any user with full control access rights can take ownership of these documents, provide the metadata if needed and get the documents checked in to make them available to all users.
- Go to the Document Library Settings >> Click on the “Manage files which have no checked in version” link under Permissions and Management group.
- Select files under “Files checked out to others:” by checking the Check the box in each file.
- Click on “Take Ownership of Selection” and confirm the prompt “Are you sure you want to take ownership of file name”.
- This makes the file available for you. Now, go to the document library and Check in the file(s).
- You may have to provide mandatory metadata or add a checked in comment. Once they are checked in, they will be visible to everyone.
PowerShell to Manage files which have no checked in version in a SharePoint Document Library:
Let’s take ownership of all checked out files and check in them using PowerShell.
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
#Variables
$WebURL="https://intranet.crescent.com"
$ListName="Documents"
#Get Objects
$Web = Get-SPWeb $WebURL
$List = $web.Lists.TryGetList($ListName)
If($List -ne $Null)
{
#Get Checked out files with no checked in versions
$CheckedOutFiles = $List.CheckedOutFiles
Write-host "Total Number of Files with No Checkin version:"$CheckedOutFiles.count
#Loop through each checked out File
ForEach ($File in $CheckedOutFiles)
{
Write-Host -f Yellow "'$($File.LeafName)' at $($File.Url) is Checked out by: $($File.CheckedOutByName)"
#Take ownership
$File.TakeOverCheckOut()
#Check in
$List.GetItemById($File.ListItemId).File.Checkin("Checked in by Administrator")
Write-host -f Green "Took Ownership and Checked in the File!"
}
}
else
{
Write-Host -f Yellow "List '$ListName' Does not Exist!"
}
SharePoint PowerShell to Manage files which have no checked in version
Let’s expand the script a bit to check-in all documents with No Checked in Version in SharePoint Site Collection level. This PowerShell find files with no checked in version, Takes the ownership, and checks them in.
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
#Site Collection Variable
$SiteURL="https://intranet.crescent.com"
#Get the Site Collection
$Site = Get-SPSite $SiteURL
#Loop through each sub-site of the site collection
ForEach($Web in $Site.AllWebs)
{
Write-host -f Yellow "Searching for Checked out Files in Web:" $Web.Url
#Loop through each list
ForEach($List in $Web.Lists)
{
#Get Checked out files with no checkin versions
$CheckedOutFiles = $List.CheckedOutFiles
#Loop through each checked out File
ForEach ($File in $CheckedOutFiles)
{
Write-Host -f Yellow "`t '$($File.LeafName)' at $($File.Url) is Checked out by: $($File.CheckedOutByName)"
#Take ownership of the file
$File.TakeOverCheckOut()
#Check in the file
$List.GetItemById($File.ListItemId).File.Checkin("Checked in by Administrator")
Write-host -f Green "`t Took Ownership and Checked in the File!"
}
}
}
In summary, We have discussed how to manage files in SharePoint that have no checked-in version. Following the script provided here, you can identify files that need to be checked in, check them in or discard check-outs, and inform users.
Thanks for the script but is there a way to check in url extension(xxx.url) files.
works like charms! Thanks for this script!
Is there any way to find all checked out file details using CSOM ?
This, this is amazing! Works perfectly and has been a life saver!
thanks!
Very detailed, much appreciated