Check In Documents With No Checked In Version Using PowerShell

When you upload a file in a SharePoint document library and the "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. Checking in these documents manually would require a lot of time.
 
Here is a PowerShell script which can help you to check in all the documents all at once. The code is self-explanatory.
  1. Add-PSSnapin *sh*  
  2. $WebUrl = Read-Host "Enter the URL of the SharePoint site"  
  3. $Library = Read-Host "Enter display name of the document library"  
  4. $UserDisplayName = Read-Host "Enter display name of the user"  
  5.   
  6.   
  7. $Web = Get-SPWeb $WebUrl   
  8. $List = $web.Lists[$Library]  
  9. $CheckedOutFiles = $list.CheckedOutFiles  
  10.   
  11. ForEach($File in $CheckedOutFiles )  
  12. {  
  13.   
  14. If($File.CheckedOutBy.DisplayName -eq $UserDisplayName )  
  15. {  
  16.     $File.LeafName  
  17.     $File.TakeOverCheckOut()  
  18.         #Check in  
  19.         $List.GetItemById($File.ListItemId).File.Checkin("Checked in by Administrator")  
  20.    }  
  21. }  
That's it. I hope ypou liked this blog and found it useful. Please give your feedback via the Comments section.