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.
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.