Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

My environment is SharePoint 2007. I have write a Power shell script to get the file names and checked out by username and their email id. I am successfully able to get these details.

Now I want to find out the check out file based on specific user name.

eg:

There is a web app called http://moss having about 80 site collection.

There is a user called UserA. he is a contributor to 10 site collection.

I want to know how many documents are checked out to these particular UserA only.

The requirement is to find out the documents Checked Out to UserA as this user left the company.

so i can check in the documents that are checked out to userA Only using Script.

Thanks in Advance.

share|improve this question
add comment

2 Answers

I had write down the script to get the checkout file by user name here is the script :

function Get-CheckedOutFiles() {
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Sharepoint")

$webapp = [Microsoft.SharePoint.Administration.SPWebApplication]::Lookup("http://moss")

foreach ($site in $webapp.Sites) {

 Write-Host "Processing Site: $($site.Url).."    
$userlogin = "domain\username"

        foreach ($web in $site.AllWebs) 

         {
           Write-Host -foregroundcolor red "Processing Web: $($web.Url)..."

             foreach ($list in ( $web.Lists | ? {$_ -is [Microsoft.SharePoint.SPDocumentLibrary]}) ) {  

               # Write-Host -foregroundcolor green "Processing List: $($list.RootFolder.ServerRelativeUrl)..."

             foreach ($item in $list.CheckedOutFiles) {
                if ($item.CheckedOutBy.LoginName -eq $userLogin) {

                $hash = @{
                “URL”=$web.Site.MakeFullUrl(“$($web.ServerRelativeUrl.TrimEnd(‘/’))/$($item.Url)”);

                “CheckedOutBy”=$item.CheckedOutBy;

                “CheckedOutByEmail”=$item.CheckedOutByEmail  

                }
            New-Object PSObject -Property $hash 

            }

            }
            foreach ($item in $list.Items) {
                if ($item.File.CheckOutStatus -ne "None" -and $item.File.CheckedOutBy.LoginName -eq $userLogin){ 

            $hash = @{
                   “URL”=$web.Site.MakeFullUrl(“$($web.ServerRelativeUrl.TrimEnd(‘/’))/$($item.Url)”);

                   “CheckedOutBy”=$item.CheckedOutBy;

                   “CheckedOutByEmail”=$item.CheckedOutByEmail  

                }

                New-Object PSObject -Property $hash 
                }
            }

        }

      $web.Dispose()
  }
 }
}


Get-CheckedOutFiles |select URL, CheckedOutBy ,CheckedOutByEmail 

Change url http://moss to your web apps and

$userlogin = username to find the file checkedout to that user.

This works on web app level.

This script give the checkout file by user when it was first upload and checked out to user which is seen only through Manage Checkout Files option under Document library settings.Such files don't show username when it pops up in power shell results.

It shows also the check out file by user during editing process.

I am not sure how much it will effect the performance as i had just run it on dev but it works well for my scenario.

Thanks

share|improve this answer
add comment

This code is deleting all SPListItems checked out by particular user and assuming that files count.

function RemoveCheckedOut([string]$userLogin)
{
    $count = 0;
    foreach ($web in (Get-SPSite -Limit All | Get-SPWeb -Limit All)) {
        Write-Host "Processing Web: $($web.Url)..."
        foreach ($list in ($web.Lists | ? {$_ -is [Microsoft.SharePoint.SPDocumentLibrary]})) {
            Write-Host "`tProcessing List: $($list.RootFolder.ServerRelativeUrl)..."
            foreach ($item in $list.CheckedOutFiles) {
                if ($item.CheckedOutBy.LoginName -eq $userLogin) {
                    $item.CheckIn("deleting");
                    $item.Delete();
                    $count++
                }
            }
            foreach ($item in $list.Items) {
                if ($item.File.CheckOutStatus -ne "None" -and $item.File.CheckedOutBy.LoginName -eq $userLogin) {
                    $item.File.CheckIn("deleting");
                    $item.File.Delete();
                    $count++
                }
            }
        }
        $web.Dispose()
    }
    write-host "$count files have deleted."
}


RemoveCheckedOut "ad2008r2\kyle"

With help of this post.

share|improve this answer
    
This code will not work for SharePoint 2007, since the Get-SPSite and Get-SPWeb commandlets are introduced for SharePoint 2010. Additionally, the goal is not to delete the ckecked out items, but to check them in. –  Matthias Jan 6 '12 at 12:29
    
I will try to modified the above script to get to work for 2007 and will try to get the list of items checked out by particular user. Thanks IAfanasov and Matthias. –  user994521 Jan 9 '12 at 23:58
    
user994521, thank for comment! It would be very helpful if you post your code. –  IAfanasov Jan 10 '12 at 6:29
    
I had write down the script to get the checkout file by user name here is the script –  user994521 Jan 11 '12 at 6:10
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.