Welcome to MSDN Blogs Sign in | Join | Help

SharePoint Thinks, Links and Clinks

SharePoint TLC as in Thinks (Thoughts and Findings), Links (to other blogs, msdn, technet, etc) and Clinks (toasts about coolness?)

News

  • Locations of visitors to this page

    These postings are provided as is with no warranties, and confers no rights. Additionally, views expressed herein are my own and not those of my employer, Microsoft.

    web tracker
    View Tadd Dawson's profile on LinkedIn
Updating the “Created By” and “Modified By” Columns in SharePoint lists using POWERSHELL

Thinks

Ever had the good old System Account show up as your author or editor, oops I mean “Created By” and “Modified By” column in SharePoint lists? Come on, you know that you have. OK, if you have and wanted to modify these, it can be done through the good old SharePoint Object Model. Sowmyan has a post on doing this in C# from a quick little app and I wanted to take the time to play with my new favorite tool (PowerShell!)

Sample Code for your PowerShell file – hint user PowerGUI Script editor for good old code completion goodness (www.PowerGui.org). This is sample code that you should add the appropriate dispose and error checking etc to. The # is the PowerShell line comment code for those learning PowerShell.

The fun thing is that this could probably be done as a ONE LINE code thing as well.

 

# Get the SharePoint Assembly
# You will need to run this on the SharePoint Server

[Reflection.Assembly]::Load("Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c")

# The site my list was in was at http://dev
# create a new object called $SPSite

$SPSite = New-Object Microsoft.SharePoint.SPSite("http://dev/")

# Make sure you have the last “/” in the url on the site
# allow $SPWeb to be the OpenWeb from the site

$SPWeb = $SPSite.OpenWeb()

# Get the list ModifyCreatedBy

$SPList = $SPWeb.Lists["ModifyCreatedBy"]

# Get the Collection of the List Items

$SPListItemCollection = $SPList.Items

# iterate the Collection

foreach ($ListItem in $SPListItemCollection)
    {

# The user in this case was Test R. Test and had a user id of 8 from the SPWeb users
#


        $SPFieldUserValue = New-Object Microsoft.SharePoint.SPFieldUserValue($SPWeb,8, "#Test R. Test")

        $ListItem["Author"] = $SPFieldUserValue                   

# Note: Editor will be the account that you are running the Powershell under unless you update # Editor as well

        $ListItem.Update()
    }

    $SPWeb.Update()

# Still TODO Disposes, Error Checking, Change to take Parameters, etc

 

Links

Clinks

  • GREAT! Thank you Sowmyan for sharing your post with the EcoSystem and providing me the motivation to do this in PowerShell
  • NOT SO GREAT! Unrelated, but my VPC had a disk error, argh.
  • GREAT! Was very straight forward in PowerShell!
Posted: Thursday, May 22, 2008 4:41 PM by tadd

Comments

Mirrored Blogs said:

Entwicklung What you need to know about AllowUnsafeUpdates (Part 1) What you need to know about AllowUnsafeUpdates

# May 28, 2008 4:16 AM

SharePoint, SharePoint and stuff said:

Direkter Download: SPPD-099-2008-06-06 Aktuell SharePointCommunityCamp September 2008 (15.9./16.9.2008)

# June 6, 2008 11:09 AM

Mirrored Blogs said:

Direkter Download: SPPD-099-2008-06-06 Aktuell SharePointCommunityCamp September 2008 (15.9./16.9.2008

# June 6, 2008 11:47 AM

Michael Greth MVP SharePoint Blog said:

Direkter Download: SPPD-100-2008-06-25 Behind the Scene - QIK Video Aktuell SharePointCommunityCamp September

# June 25, 2008 11:06 AM

SharePointPodcast.de said:

Direkter Download: SPPD-100-2008-06-25 Behind the Scene - QIK Video Aktuell SharePointCommunityCamp September

# June 25, 2008 11:07 AM

Mirrored Blogs said:

Direkter Download: SPPD-100-2008-06-25 Behind the Scene - QIK Video Aktuell SharePointCommunityCamp September

# June 25, 2008 11:51 AM

Lordi said:

Thank you very much, now I can get my self-updating inventory list done

# October 24, 2008 3:44 PM
Anonymous comments are disabled
Page view tracker