2

I am wanting to change the editor and author of a document in a document library in O365 using CSOM powershell. I have managed to change the dates like this :

$Upload = $List.RootFolder.Files.Add($FileCreationInfo)
$Context.Load($Upload)
$Context.ExecuteQuery()

$ListItem = $Upload.ListItemAllFields;

$Listitem["Modified"] = "2013-07-02T00:00:00"
$Listitem["Created"] = "2013-07-02T00:00:00"

$ListItem.Update()
$Context.Load($Upload)
$Context.ExecuteQuery()

but I am stuck with how to add people as $Listitem["Editor"] = "John Smith" doesn't work

  • Do you want to set "Editor" and "Author"(user columns) column or "Created" or "Modified" (date columns)? – Kalpesh Vaghela Jun 2 '15 at 9:25
  • all I have done the create and modified which works correctly I am stuck on getting Editor and Author to work – jamesd Jun 2 '15 at 9:43
1

Author and Editor fields are lookup fields. If you don't know the User ID you can get it by doing something like:

$user = $context.Web.EnsureUser($userEmail)
$context.Load($user)
$context.ExecuteQuery()

Then in your code you can set the lookup value. By providing a formatted string as follows:

$item["Editor"] = "{0};#{1}" -f $user.Id, $user.LoginName

Interestingly, it might seem that using a FieldUserValue is the appropriate way to do this:

$userValue = New-Object Microsoft.SharePoint.Client.FieldUserValue
$userValue.LookupId = $user.Id
$item["Editor"] = $userValue

But that fails (or it does for me).

UPDATE: I created a blog with full PowerShell source here: http://www.threewill.com/update-sharepoint-online-system-fields-via-csom/

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.