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

I have a sharepoint 2007 list and it has many items, I want to update a column in an item thro' a powershell script even if the item is current edited/locked by someone else.

Is it posssible?

share|improve this question
add comment

2 Answers

You can check for the list items File property for check out status, and depending on different conditions check file in or undo checkout (for example undoing checkout when the file has no previous versions will throw an exception, so here it may make more sense to either check in or delete).

Check out the UndoCheckOut() method here http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spfile.undocheckout(v=office.12).aspx

I would definately do this in PowerShell compared to a C# console application. Its much faster once you get the hang of it! In SP2007 theres a little overhead since the cmdlets doesnt exist OOB.

Heres some untested boilerplate code (as in: add exceptions and proper checks). Remember you have to dispose the methods you create yourself:

[Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")

try
{
    $sites = new-object Microsoft.SharePoint.SPSite("http://extranet.issworld.com/teamrooms/admin")
    $site = $sites.OpenWeb()
    $list = $site.Lists["Documents"];
    if ( $list )
    {
        Write-Host ("Found List [$($list.Title)]")
        $list.Items | Where-Object{$_.File.CheckOutStatus -ne "None"  -and $_.File.CheckedOutBy -ne "domain\myLogin"} | ForEach-Object{$_.File.UndoCheckOut()}

    }

}
finally
{
    if ($sites)
    {
        $sites.Dispose()
    }
    if ($site)
    {
        $site.Dispose() 
    }

}
share|improve this answer
    
as i mentioned,its a custom list with few list columns. I wonder if there is a way to find whether the list item is locked using any of its columns except the file field. –  Karthikeyan Dec 25 '10 at 2:22
    
please explan how you defined "item is locked". Do you mean you have enabled approval on the list? (AFAIK there is no checking out of custom list items) –  Anders Rask Dec 27 '10 at 9:08
    
I am not able to edit/update the item if it is being edited by someone else. –  Karthikeyan Dec 28 '10 at 13:35
add comment

I suppose anything is possible. But it will be quite complicated and probably worse than the equivalent C# code. You will be working directly with the object model, so it might be easier to write a console app in C#.

share|improve this answer
    
ok, but its not allowing me to update the list column if the item is already locked by someone else. Can you suggest me how it can be done using c#? –  Karthikeyan Dec 22 '10 at 18:39
    
yes its a hidden column... –  Karthikeyan Dec 22 '10 at 18:39
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.