0

I am unable to delete a locked file because it says it is checked out by a user. We verified the only user that has access does NOT have this open or checked out. This is in the 'Form Templates' Library that cannot be deleted from the browser.

I also looked into the Library Setting'Manage files which have no checked in version', but nothing shows up there. Any ideas on how to delete this file and/or library? Powershell or another workaround?

enter image description here

0

Check in the file then delete it:

#Variables for Processing
$SiteURL = "https://tenant.sharepoint.com/sites/michael"
$LibraryName="doc"
$ItemId="1"

$UserName="michael"
$Password ="xxx"

#Setup Credentials to connect
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName,(ConvertTo-SecureString $Password -AsPlainText -Force))

#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = $Credentials

#Get the list by title
$List=$Ctx.web.Lists.GetByTitle($LibraryName)

#Get the item to delete by ID
$Item=$List.GetItemById($ItemId)
#Get the file to delete
$File=$Item.File

#Check in and delete the file
$File.CheckIn("1",1)
$File.deleteobject()
$Ctx.ExecuteQuery()
1

Check for file checked out status and release lock if any

$spWeb = Get-SPWeb http://prinhyltphp0317/
$listName = "text"
$list = $spWeb.Lists |? {$_.Title -eq $listName}
foreach ($item in $list.Items) 
{
  $itemFile = $item.File
  if( $itemFile.CheckOutStatus -ne "None" )
  { 
           $itemFile.ReleaseLock($itemFile.LockId)
  }
}

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.