Forum Discussion

emalac's avatar
emalac
Copper Contributor
Jan 07, 2020

PowerShell script to unlock documents in SharePoint Online

Hi,
I've a DocumentLibrary in which documents are required to be checked out but when I create a new document, as Admin, I can't to check it in because required fields are empty and, at the same time, I can't edit them because there is a lock created by myself.
 
I've read I can't do anything by UI and I should wait untill 10 minutes before to proceed saving properties, someone says it can take more than 10 minutes but, anyway, I can't wait neither 10 minutes: I would like to write a powershell script to launch every time I need to unlock my documents but I can't find something that could work with SharePoint Online (only for SharePoint Server): any advice?
 
Thanks in advance.
  • Helloemalac ! 
    You could try and use the PNP mdule 

     

    #Variables

    $Cred = Get-Credential

    $SiteURL = "https://domain.sharepoint.com"

    $FileLocation ="/Documents/File.docx"

     

    #Connect to PNP Online

    Connect-PnPOnline -Url $SiteURL -Credentials $Cred

     

    #Check In a File

    Set-PnPFileCheckedIn -Url $FileLocation-CheckinType MajorCheckIn -Comment "Checked In at $(Get-Date)"

Resources