Thursday, October 6, 2016

Cannot update Created By (Author) field through powershell

Add-PSSnapin Microsoft.SharePoint.PowerShell -EA SilentlyContinue
$SPWeb = Get-SPWeb "http://sharepoint";
$SPList = $SPWeb.GetList("http://sharepoint/Lists/Favorites");
$userName = "i:0#.w|[domain]\[username]";
$user = Get-SPUser -web $SPWeb -Identity $userName;

$SPListItem = $SPList.Items.Add();
$SPListItem["URL"] = "http://www.peakfinders.com";
$SPListItem["Author"] = $user;
$SPListItem.Update();

No comments:

Post a Comment