2

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

I tried:

$user=$ctx.Web.EnsureUser("[email protected]")

$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 Answers 2

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="[email protected]"
$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
    Aug 8, 2018 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
    Aug 8, 2018 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, 2018 at 12:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.