Home > PowerShell, SharePoint Administration, SharePoint Advancements > Taking Ownership and Checking In Documents With No Checked In Versions in SharePoint 2007 Using PowerShell.

Taking Ownership and Checking In Documents With No Checked In Versions in SharePoint 2007 Using PowerShell.

I recently blogged about how to Get a listing of All Checked-Out Documents with No Checked-In Versions in SharePoint 2007 Using PowerShell.  That blog posting can be found here — http://jshidell.com/2012/06/21/getting-a-list-of-all-checked-out-files-with-no-checked-in-versions-in-sharepoint-2007-using-powershell/

Now i’m going to add a little more to that blog with the ability to Take Ownership and also Check in the documents at the same time.  This can come into handy if you have alot of documents that are checked out and don’t belong to you, and you need them checked in.  Possibly for migration purposes.

Below is the modified script on how to accomplish this.

——————————————————————————————————————————————————————————–
Void [System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.SharePoint”)

function CheckedOutItems()
{
$url=Read-Host “Please Enter In Site Url”
”SiteURL ‘t” + “FileName ‘t” + “CheckedOutTo ‘t” + “ModifiedDate ‘t” + “Version” >> c:\temp\checkedoutfiles.csv
$site = New-Object Microsoft.SharePoint.SPSite($url)
$webs = $site.AllWebs

foreach($web in $webs)
{
$listCollections=$web.Lists
foreach($list in $listCollections)
{
if($list.BaseType.ToString() -eq “DocumentLibrary”)
{
$dList=[Microsoft.SharePoint.SPDocumentLibrary]$list
$items = $dList.Items
$files = $dList.CheckedOutFiles
foreach($file in $files
{
$wuse=$file.DirName.Substring($web.ServerRelativeUrl.Length)
$web.Url + “‘t” + $wuse + “‘/” + $file.LeafName + “‘t” + $file.CheckedOutBy.Name + “‘t” + $file.TimeLastModified.ToString() + “‘t” + “No Checked In Version” >> c:\temp\checkedoutfiles.csv
$file.TakeOverCheckOut() #Take ownership of checked out document
}
foreach($item in $list.Items)
{
$item.File.Checkin(“Checked in by Systems Administrator”) #Check document in
if (($list.CheckedOutFiles | Where {$_.ListItemId -eq $item.ID}) -ne $null) {continue}

}
}
}
$web.Dispose()
}
$site.Dispose()
}

CheckedOutItems

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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

%d bloggers like this: