What you will find here

If you are one of those multi hat kind of person you might want to take a look here.
Some of the sections here will cover: SharePoint, SQL, Server, VB Script, Batch files, PCI Compliance

Icon

Icon

Wednesday, March 6, 2019

Uncheck or Unlock Document or Page SharePoint Online - power shell

after trying A LOT to discard changed on a page by a user, I finally got it.

This is actually working like a charm for pages and documents.



Connect-SPOService –Url "YOUR ADMIN URL"


{
$siteUrl = "YOUR SITE URL"
$siteUrl
$username = "USER HERE"
$password = "PASS HERE"
$SPOCredentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($userName,(ConvertTo-SecureString $Password -AsPlainText -Force))

$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
$Ctx.Credentials = $SPOCredentials
$web = $Ctx.Web
$ctx.ExecuteQuery()


# Load the up list
$lookupList = $ctx.Web.Lists.GetByTitle("YOUR LIBRARY")
$ctx.Load($lookupList)
# Prepare the query
$query = New-Object Microsoft.SharePoint.Client.CamlQuery
$query.ViewXml = '<View Scope="RecursiveAll"><RowLimit Paged="TRUE">1000</RowLimit></View>'

  $listItems = $lookupList.getItems($query)
    $ctx.Load($listItems)
    $ctx.ExecuteQuery()
    $query.ListItemCollectionPosition = $listItems.ListItemCollectionPosition

#Load File
$file = $ctx.Web.GetFileByServerRelativeUrl("RELATIVE URL OF PAGE HERE");
        #Relative URL of document is : sample.. /sites/mysite/SitePages/Home.aspx
        $ctx.Load($file)
$Ctx.ExecuteQuery()
$file.UndoCheckOut()
$file.Update()
$Ctx.ExecuteQuery()
}


I hope this helps. !!!


No comments:

Post a Comment