4

I'm trying to undo a checkout with PowerShell but the function name doesn't seem to be recognized. Here is the code that I used.

$dList = [Microsoft.Sharepoint.SPDocumentLibrary]$list
            $items = $dList.Items
            $files = $dList.CheckedOutFiles
            foreach($file in $files)
            {

                $wuse = $file.DirName.Substring($web.ServerRelativeUrl.Length)
                Write ($web.Url+ "`t" + $wuse+"`/" + $file.LeafName +  "`t" + $file.CheckedOutBy.Name + "`t" + $file.TimeLastModified.ToString()+"`t" + "No Checked In Version" )

                $file.UndoCheckOut;


            }
            foreach($item in $items)
            {
                if ($item["Checked Out To"] -ne $null)
                {
                    $splitStrings = $item["Checked Out To"].ToString().Split('#')

                    Write ($web.Url+ "`t" + $item.Url + "`t" + $splitStrings[1].ToString() + "`t" + $item["Modified"].ToString() +"`t" + $item["Version"].ToString())

                    $item.UndoCheckOut;
                }
            }

Here is how I enable the powershell snap-in

Add-PSSnapin "Microsoft.SharePoint.PowerShell"
  • Could u share the error msg which u are getting. – Pushpendra Nov 11 '13 at 17:53
7

I believe

$file.UndoCheckOut;

Should in fact be...

$file.UndoCheckOut()

The same goes for items.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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