Quantcast
Channel: SharePoint Diary
Viewing all articles
Browse latest Browse all 1058

Find All Checked Out Files and Check-In them Back

$
0
0
I'm Sharing one of the PowerShell script I used in MOSS 2007 to SharePoint 2010 migration. Since its very difficult to check-in back all the checked-out files after migration, its a best practice to check-in all checked out files prior.

This PowerShell script will Scans, Generates Report and check-in all checked out files. Run this script with Farm Administrator privileges.

 
# For MOSS 2007 compatibility
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")

#Region MOSS2007-CmdLets

Function Get-SPWebApplication()
{   
  Param( [Parameter(Mandatory=$true)] [string]$WebAppURL )
  return [Microsoft.SharePoint.Administration.SPWebApplication]::Lookup($WebAppURL)
}

Function global:Get-SPSite()
{
  Param( [Parameter(Mandatory=$true)] [string]$SiteCollURL )

   if($SiteCollURL -ne '')
    {
    return new-Object Microsoft.SharePoint.SPSite($SiteCollURL)
   }
}
 
Function global:Get-SPWeb()
{
 Param( [Parameter(Mandatory=$true)] [string]$SiteURL )
  $site = Get-SPSite($SiteURL)
        if($site -ne $null)
            {
               $web=$site.OpenWeb();
            }
    return $web
}
#EndRegion

 Function GetCheckedOutFiles()
 {  
    #Define 'Web Application URL' as Mandatory Parameter
    Param( [Parameter(Mandatory=$true)] [string]$WebAppURL )
 
 #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 CheckedOutFiles.txt

 #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)
   {
            #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 eadh 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 where versioning size > 0MB!
                        "$($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 CheckedOutFiles.txt -Append
       #*** Uncomment the below line to Check-in****#
       $ListItem.File.Checkin("Checked in by Administrator")
      }
                    }
                }
            }
   $Web.Dispose()          
        }
 $Site.Dispose()          
    }
    #Send message to output console
    write-host "Checked out Files Report Generated Successfully!"
}

#Call the Function to Get Checked-Out Files
GetCheckedOutFiles "http://sharepoint.company.com"

Bulk Check-In all checked-out files in Site collection:
If you want to check-in all checked-out files by you, use "Content and Structure" link under site settings. You have the option "Checked Out to Me" which lists all files checked-out to you. Just select the desired files and click Check-in from actions menu.

Viewing all articles
Browse latest Browse all 1058

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>