1

I need to update the CreatedBy(Author) field using CSOM Powershell Sharepoint Online.

I tried:

$user=$ctx.Web.EnsureUser("xxx@aa.onmicrosoft.com")

$ctx.Load($user)

$ctx.ExecuteQuery()

$listItem["Author"]=$user

$listItem.Update()

$ctx.ExecuteQuery()

But this is not updating .I have given mailid to EnsureUser() method because I have only mailId of the user.

can anyone help me with correct solution.

2

Try the below PowerShell Script to can Update Created By / Modified By Fields values using PowerShell CSOM in SharePoint Online

#Load SharePoint CSOM Assemblies
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"

##Variables for Processing
$SiteUrl = "https://crescent.sharepoint.com/sites/sales/"
$ListName= "Projects"
$ID=6
$UserID="Salaudeen@crescent.com"
$TimeStamp = "2015/12/01 02:10:00 AM"

#Get Credentials to connect
$Cred = Get-Credential
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)

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

#Get the User
$User = $Ctx.Web.EnsureUser($UserID)
$ctx.Load($user)

#Get the list Item
$List=$Ctx.Web.Lists.GetByTitle($ListName)
$ListItem = $List.GetItemById($ID)
$Ctx.Load($ListItem)

#Update Created by & Modified By
$ListItem["Author"] = $User
$ListItem['Editor'] = $User

#Set Created on & Modified on Time values
$ListItem["Created"] =  $TimeStamp
$ListItem["Modified"] = $TimeStamp

#Update List item
$ListItem.Update()
$ctx.ExecuteQuery()

Write-host "Metadata values updated Successfully!" -f Green

Credit to: SharePoint Online: Update Created By / Modified By, Created At / Modified At Field values using PowerShell CSOM

1
  • This is working fine for custom list,but I am updating for a Page in Page library.I dont know why it is not getting updated for a page.But showing modified few seconds ago. – Swetha Paritala Aug 8 '18 at 5:27
0

It works for me (on SP2016 OnPrem) only when I change two fields at the same time

$listItem["Author"]=$user
$listItem["Editor"]=$user

just try it out, maybe it works also for you

2
  • this is working for me for custom lists not for Page lib and Document library.I am working for SPOnline site. – Swetha Paritala Aug 8 '18 at 12:41
  • This is working for me for both of types. It seems like SPO is (once again) slightly different than OnPrem... – MM8903 Aug 8 '18 at 12:48

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.