2

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?

2 Answers 2

1

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() 
    }

}
3
  • 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. Commented Dec 25, 2010 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) Commented Dec 27, 2010 at 9:08
  • I am not able to edit/update the item if it is being edited by someone else. Commented Dec 28, 2010 at 13:35
0

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#.

2
  • 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#? Commented Dec 22, 2010 at 18:39
  • yes its a hidden column... Commented Dec 22, 2010 at 18:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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