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"