locked
edit created by column using power shell RRS feed

  • Question

  • I wrote the following script to update the created by column of the documents in one of my document libraries:



    Add-PSSnapin Microsoft.SharePoint.PowerShell -EA SilentlyContinue
    $SPWeb = Get-SPWeb "";
    $SPList = $SPWeb.Lists[""]
    $userName = "";
    $user = Get-SPUser -web $SPWeb -Identity $userName;
    $userString = "{0};#{1}" -f $user.ID, $user.UserLogin.Tostring()
    $SPListItemCollection = $SPList.Items

    foreach ($ListItem in $SPListItemCollection)

    {

    $ListItem["Author"] = $userString;
    $ListItem.UpdateOverwriteVersion()
    }

    The script runs successfully but when viewing the metadata from the browser I noticed the values don't get updated

    Any ideas ?

    Wednesday, November 11, 2015 12:10 PM

All replies

  • hi

    insert in the loop

    $listItem.update()


    Romeo Donca, Orange Romania (MCSE, MCITP, CCNA) Please Mark As Answer if my post solves your problem or Vote As Helpful if the post has been helpful for you.

    Wednesday, November 18, 2015 2:51 PM
  • script run correctly becouse you write SilentlyContinue

    correct code:

    Add-PSSnapin Microsoft.SharePoint.PowerShell
    $SPWeb = Get-SPWeb "";
    $SPList = $SPWeb.Lists[""]
    $userName = "";
    $user = Get-SPUser -web $SPWeb -Identity $userName;
    $userString = New-Object Microsoft.SharePoint.SPFieldUserValue($web, $user.ID, $user.Name)
    $SPListItemCollection = $SPList.Items

    foreach ($ListItem in $SPListItemCollection)

    {

    $ListItem["Author"] = $userString;
    $ListItem.UpdateOverwriteVersion()
    }

    Thursday, September 17, 2020 4:26 PM