0

We have 50,000+ has been checked out by users. We need to check-in back. Document library contain sub folders inside. Can anyone please powershell script for us.

Example: Document library name "Test lib", under that test1 folder, under that test2 folder, under that test3 folder likewise. on test8 or 9 folder checked-out file exist. We tried below script, no error and nothing coming. Just an seconds its coming completed. Seems something we are missing. Please suggest me.


Add-PSSnapin Microsoft.SharePoint.PowerShell -ea 0 
 
Function CheckInAllDocs([string]$DoclibURL){ 
    if ($docliburl.EndsWith("/")){ 
        $docliburl = $docliburl.Substring(0,$docliburl.length-1) 
    } 
    $web = get-spweb -identity $docliburl.Substring(0,$docliburl.LastIndexOf("/")) 
    $doclib = $web.lists |where {$_.RootFolder.Name -eq $docliburl.Substring($docliburl.LastIndexOf("/")+1,$docliburl.length-$docliburl.LastIndexOf("/")-1)} 


    ForEach($item in $doclib.checkedoutfiles){ 
        #$item.TakeoverCheckout() 
        $doclib.GetItemById($item.ListItemId).file.CheckIn("Checked in by Script") 
        write-host "$($item.LeafName) has been checked in" 
    } 
} 
#To use enter the location of a document library 
CheckInAllDocs "http://server.com/apps/Files"

1 Answer 1

0

I understand you want to check in all check-out files under a library, you may have a try below cmdlets:

   function CheckInDocument([string]$url)
    {
        $spWeb = Get-SPWeb $url
        $getFolder = $spWeb.GetFolder("Test lib")
        $getFolder.Files | Where { $_.CheckOutStatus -ne "None" } | ForEach
        {
            Write-Host "$($_.Name) is Checked out To: $($_.CheckedOutBy)"
            $_.CheckIn("Checked In By Administrator")
            Write-Host "$($_.Name) Checked In" -ForeGroundColor Green
        }
        $spWeb.Dispose()
    }

BR

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.