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.
- 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")
- }
- }
That's it. I hope ypou liked this blog and found it useful. Please give your feedback via the Comments section.