5

We have in our environment installed Gary LaPointe powershell cmdlets and I found this script

Get-SPCheckedOutFiles 

which returns all checkedout files, now I need to forcely check them in, not sure how to do though that in powershell.

http://blog.falchionconsulting.com/index.php/2011/06/getting-and-taking-ownership-of-checked-out-files-using-windows-powershell/

2
  • You want to checkin aa files in site or a particular document library?
    – Aanchal
    Jun 13, 2014 at 10:28
  • all files in a document library Jun 13, 2014 at 10:30

3 Answers 3

9

You can use the following code:

function CheckInDocument([string]$url)
{
    $spWeb = Get-SPWeb $url
    $getFolder = $spWeb.GetFolder("Shared Documents")
    $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()
}

Here’s an example on running the function:

CheckInDocument http://SP

OR you can Try :

$spWeb = Get-SPWeb http://prinhyltphp0317/
$listName = "text"
$list = $spWeb.Lists |? {$_.Title -eq $listName}
foreach ($item in $list.Items) 
{
    $itemFile = $item.File
    if( $itemFile.CheckOutStatus -ne "None" )
    { 
        $itemFile.CheckIn("Automatic CheckIn. (Administrator)")
    }
}
$spWeb.Dispose()
5
  • and what are the parameters? screencast.com/t/PcyNspl0 Jun 13, 2014 at 12:38
  • still not working, check screeenshot, script seems to have something wrong Jun 16, 2014 at 9:13
  • Please share the screenshot.
    – Aanchal
    Jun 16, 2014 at 9:16
  • lol see url above Jun 16, 2014 at 9:18
  • I Have update the answer, You can try that and check if you still face issue
    – Aanchal
    Jun 16, 2014 at 10:03
3

This will also check all sub folders and check in if any file(s) are checked out

$web = Get-SPWeb "http://vm01"
$folder = $web.GetFolder("Style Library")
function GetFilesNuv($fldrs,$space){
    write-host $space -nonewline
    write-host $fldrs.name -backgroundcolor White -foregroundcolor Black
    $fldrs.Files | Where { $_.CheckOutStatus -ne "None" }  |ForEach-Object {
    write-host ($space,$_.Name,$_.CheckedOutBy) -Separator "  " -foregroundcolor Red
    $_.CheckIn("");
    }
    $fldrs.SubFolders |ForEach-Object {
    GetFilesNuv $_ ($space + "  ") ;
    }
}
GetFilesNuv $folder "  " 
$web.Dispose() 
2

I found this solution the so far the best as it goes through a web applications (including subfolders etc). Worked with SharePoint 2016 too.

http://www.sharepointdiary.com/2013/02/find-all-checked-out-files-and-check-in.html

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

Function CheckIn-AllCheckedOutFiles()
{  
    #Define 'Web Application URL' as Mandatory Parameter
    Param( 
    [Parameter(Mandatory=$true)] [string]$WebAppURL,
    [Parameter(Mandatory=$true)] [string]$ReportOutput
    )

    #Get the Web Application
    $WebApp = Get-SPWebApplication $WebAppURL

    #Write the CSV Header - Tab Separated
    "Site Collection Name `t Site Name`t Library `t File Name `t File URL `t  Last Modified `t Checked-Out By" | Out-file $ReportOutput

    #Arry to Skip System Lists and Libraries
    $SystemLists =@("Converted Forms", "Master Page Gallery", "Customized Reports", "Form Templates", "List Template Gallery", "Theme Gallery", 
           "Reporting Templates", "Solution Gallery", "Style Library", "Web Part Gallery","Site Assets", "wfpub")

    #Loop through each site collection
    ForEach($Site in $WebApp.Sites)
    {
        #Loop through each site in the site collection
        ForEach($Web in $Site.AllWebs)
        {
            Write-host "Processing Site:" $web.Url
            #Loop through each document library
            Foreach ($List in $Web.GetListsOfType([Microsoft.SharePoint.SPBaseType]::DocumentLibrary))
            {
                #Get only Document Libraries & Exclude Hidden System libraries
                if ( ($List.Hidden -eq $false) -and ($SystemLists -notcontains $List.Title) )
                {
                    #Loop through each Item
                    foreach ($ListItem in $List.Items) 
                    {
                        If( ($ListItem.File.CheckOutStatus -ne "None") -and ($ListItem.File.CheckedOutByUser -ne $null))
                        {
                            #Log the data to a CSV file
                            "$($Site.RootWeb.Title) `t $($Web.Title) `t $($List.Title) `t $($ListItem.Name) `t $($Web.Url)/$($ListItem.Url) `t  $($ListItem['Modified'].ToString()) `t  $($ListItem.File.CheckedOutByUser)" | Out-File $ReportOutput -Append
                            Write-host -f Yellow "Found a Checked out file at: $($Web.Url)/$($ListItem.Url)"

                            #Check in the file
                            $ListItem.File.Checkin("Checked in by Administrator")
                        }
                    }
                }
            }
        }
    }

    #Send message to output console
    write-host -f Green "Checked out Files Report Generated Successfully!"
}

#Call the Function to Get Checked-Out Files and check them in
CheckIn-AllCheckedOutFiles -WebAppURL "http://intranet.crescent.com" -ReportOutput "C:\Temp\CheckedOutFiles.txt"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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