Check-in a page using pnp without updating the modified by field

Tanmoy Das 806 Reputation points
2021-01-11T00:37:52.687+00:00

Hi,

Can I check in a page without updating the modified by field using pnp?

Thanks

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
11,231 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Allen Xu_MSFT 13,836 Reputation points
    2021-01-11T09:31:55.62+00:00

    Hi anonymous user,

    I tried to use Set-PnPFileCheckedIn to check in a page, however it seemed that pages were not supported to use this cmdlet.
    55237-3-1.png

    So we have to use CSOM PowerShell instead to check in a page firstly and then we can use PnP to set Modified By field. Please refer to my PowerShell Command.

    Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"  
    Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"  
         
    #Parameters  
    $SiteURL= "https://xxx.sharepoint.com/sites/xxx"  
    $LibraryName="Site Pages"  
    $ItemID="8"  
    $ModifiedBy="******@xxx.onmicrosoft.com"  
      
    #Setup Credentials to connect  
    $Cred = Get-Credential  
    $Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)  
      
    #Setup the context  
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)  
    $Ctx.Credentials = $Cred  
      
    #Get the web, List, Item and File   
    $Web=$Ctx.Web  
    $List=$web.Lists.GetByTitle($LibraryName)  
    $Item=$list.GetItemById($ItemID)  
    $File=$Item.File  
      
    #Get the File to context  
    $Ctx.Load($File)  
    $Ctx.ExecuteQuery()  
               
    #check if the file is checked out  
    If($File.CheckOutType -eq "None")  
    {  
        write-host "Document is not checked out Already!" -f Red  
    }  
    else  
    {  
        #Check in the file: sharepoint online force check in powershell  
        $File.CheckIn("Checked-in from PowerShell",[Microsoft.SharePoint.Client.CheckinType]::MajorCheckIn)  
        $Ctx.ExecuteQuery()  
           
        write-host "Document has been checked-in successfully!" -f Green  
    }  
      
    Connect-PnPOnline -Url $SiteURL -UseWebLogin  
      
    Set-PnPListItem -List $LibraryName -Identity $ItemID -Values @{"Editor"= $ModifiedBy}  
    

    Note: Please remember to replace the parameters with your own. Assign the ID of the page in the library to $ItemID and assign the user account that you want the modifieldby field to remain unchanged to $ModifiedBy.


    If an Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.