Check in all the files which have no checked in version history

Save and run the below code as PowerShel script

$site = New-Object Microsoft.SharePoint.SPSite(“http://contoso/sites/teamsite”)

$root = $site.allwebs[0]

$folder = $root.GetFolder(“test2”)


# Function Set-CheckInFolderItems is a recursive function

# that will CheckIn all items in a list recursively

# You must take ownership of files using farm account prior to running this script


function Set-CheckInFolderItems([Microsoft.SharePoint.SPFolder]$folder)


# Create query object

$query = New-Object Microsoft.SharePoint.SPQuery

$query.Folder = $folder

# Get SPWeb object

$web = $folder.ParentWeb

# Get SPList

$list = $web.Lists[$folder.ParentListId]

# Get a collection of items in the specified $folder

$itemCollection = $list.GetItems($query)

# If the folder is the root of the list, display information

if ($folder.ParentListID -ne $folder.ParentFolder.ParentListID)


Write-Host(“Recursively checking in all files in ” + $folder.Name)


# Iterate through each item in the $folder

foreach ($item in $itemCollection)


# If the item is a folder

if ($item.Folder -ne $null)


# Write the Subfolder information

Write-Host(“Folder: ” + $item.Name + ” Parent Folder: ” + $folder.Name)

# Call the Get-Items function recursively for the found sub-solder

Set-CheckInFolderItems $item.Folder


# If the item is not a folder

if ($item.Folder -eq $null)


if ($item.File.CheckOutType -ne “None”)


if ($item.File.Versions.Count -eq 0)


# Check in the file

Write-Output “Check in File: “$item.Name” Version count ” $item.File.Versions.Count -foregroundcolor Green

$item.File.CheckIn(“Checked in By Administrator”)






$web = $null


Set-CheckInFolderItems $folder | Ft -autosize |Out-string -width 4096 >>C:\output.txt


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s