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 2013?
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 a administrator, you can take control over those files with "Manage files which have no checked in version" link in the library settings.

How to Take the 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 "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.
sharepoint powershell manage files which have no checked in version


PowerShell to Manage files which have no checked in version in a SharePoint Document Library:
Lets take ownership of all checked out files and check in them using PowerShell.
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
  
#Variables
$WebURL="http://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
Lets 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="http://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!"
            }
    }
}
PowerShell to Manage Files Which Have No Checked in Version in SharePoint PowerShell to Manage Files Which Have No Checked in Version in SharePoint Reviewed by Salaudeen Rajack on July 11, 2017 Rating: 5

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.