Sharepoint - how to checkin all checked out files via powershell?

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()

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() 

Tags:

Powershell