Wed. Jun 8th, 2022
Function Check-in-Files([String]$WebDomain,[String]$sprint,[String]$srcURL,[String]$dstURL,[String]$SiteTitle,[String]$ReportOutput, $SummaryFile, $choice, $Credentials, $SPOCredentials)


        $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($srcURL);
        $ctx.Credentials = New-Object System.Net.NetworkCredential($src_Username, $Networkpassword)

        #Get the Web
        $Web = $Ctx.Web
        $Timestamp = GetTimeStamp
        #Get All Lists from the web
        $Lists = $Web.Lists
        #Prepare the CAML query
        $Query = New-Object Microsoft.SharePoint.Client.CamlQuery
        $Query.ViewXml = "@
        <View Scope = 'RecursiveAll'>
        <RowLimit Paged='True'>$BatchSize</RowLimit>
                <IsNotNull><FieldRef Name='CheckoutUser' /></IsNotNull>

        #Array to hold Checked out files
        $CheckedOutFiles = @()
        Write-host -f Yellow "Processing Web:"$Web.Url
        #Iterate through each document library in the web
        ForEach($List in ($Lists | Where-Object {$_.BaseTemplate -eq 101 -or $_.BaseType -eq "GenericList" }) )
            $CurrentList = $List.Title
            $BaseType = $List.BaseType
            if ($Global:listExclusions.Contains($List.Title) -eq $false)

             Write-host -f Yellow "Processing Document Library:"$List.Title
             #Exclude System Lists

               If($List.Hidden -eq $False)
 #       if($list.title -eq "Testing"){                
                #Batch Process List items
                Do {
                        $ListItems = $List.GetItems($Query)
                        $Query.ListItemCollectionPosition = $ListItems.ListItemCollectionPosition

                        #Get All Checked out files
                        ForEach($Item in $ListItems)
                            #Get the Checked out File data
                        $File = $Web.GetFileByServerRelativeUrl($Item["FileRef"])
                        $CheckedOutByUser = $File.CheckedOutByUser

                        if($CheckedOutByUser.LoginName -ne $null -and $CheckedOutByUser.LoginName -ne "SHAREPOINT\system")
                            Write-Host -f Green "Found a Checked out File '$($File.Name)' at $WebDomain$($Item['FileRef']), Checked Out By: $($CheckedOutByUser.LoginName)"
                            $CheckedOutFiles += New-Object -TypeName PSObject -Property @{
                                                FileName = $File.Name
                                                List = $List.Title
                                                Checkedoutstatus = "Checked Out"
                                                Location = $WebDomain+$Item['FileRef']
                                                CheckedOutBy = $CheckedOutByUser.LoginName
                                                CheckedoutTo = $CheckedOutByUser.Email}
                            #check in file programmatically     
                            $File.CheckIn("Checked-in By Administrator through PowerShell!", [Microsoft.SharePoint.Client.CheckinType]::MajorCheckIn)  
                            Write-Host -f Green "File '$($File.Name)' Checked-In Successfully!"
                          write-host -f Red "Error finding file!" $File.Name $_.Exception.Message 
                    }#End Foreach

                }While($Query.ListItemCollectionPosition -ne $Null) #End Do
#} # if Testing
                     if($BaseType -ne "GenericList")
                    write-host -f Red "Error connecting to List $CurrentList Use Sharegate UI to capture Checked out files on this list." $_.Exception.Message
                    $Summaryoutput = "$Sprint,$srcURL,$SiteTitle,$BaseType,$CurrentList"
                    Add-Content $SummaryFile $Summaryoutput 
        If($CheckedOutCounter -gt 0)
            #Export the Findings to CSV File
            $ReportFullPath = $ReportOutput + '\' + $SiteTitle + '_' + $CheckedOutCounter.ToString() +  '_CheckedOutFiles ' + $Timestamp + '.csv'
            write-host Saving to $ReportFullPath - $CheckedOutCounter -ForegroundColor Green
            $CheckedOutFiles| Export-CSV $ReportFullPath -NoTypeInformation -Append
            #$URLfromiManager = Get-Site-From-iManager -SiteTitle $SiteTitle -credentials $credentials
            #write-host "SiteURL from iManager" $URLfromiManager

            IF($choice -eq $true)
                $ReportFullPath = $ReportOutput + '\' + $SiteTitle + '_' + $CheckedOutCounter.ToString() +  '_MigratedCheckedInFiles ' + $Timestamp + '.csv'
                MigrateCheckedInFiles -srcURL $srcURL -dstURL $dstURL -SiteTitle $SiteTitle -List $List.title -ReportOutput $ReportFullPath -Credentials $Credentials -SPOCredentials $SPOCredentials


        }#For EAch
    Catch {
        write-host -f Red "Error Generating Checked Out Files Report!" $_.Exception.Message

This website uses cookies. By continuing to use this site, you accept our use of cookies.