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.
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It only takes a minute to sign up.
Sign up to join this communityWe 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.
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()
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"