Change user name in created/modified by column in all the list/library in site with appropriate user name using powershell in sharepoint 2010:
#Get the SharePoint Assembly
# You will need to run this on the SharePoint Server
[Reflection.Assembly]::Load(“Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c”)
# The site my list was in was at http://demoserver
# create a new object called $SPSite
$SPSite = New-Object Microsoft.SharePoint.SPSite(“https://www.myserver.com/entis/build1/sitename/subsite/”)
# 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[“Shared Documents”]
# Get the Collection of the List Items
#$SPListItemCollection = $SPList.Items
# iterate the Collection
[Microsoft.SharePoint.SPListCollection] $lists = $SPWeb.Lists
# iterate the list and libraries
#[Microsoft.SharePoint.SPList] $list = $null
[int] $iList = 0
for( $iList=0; $iList -lt $lists.Count; $iList++)
{
$SPList = $lists[$iList]
$SPListItemCollection = $SPList.Items
Write-Host $SPList
# 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,1,”#Vaibhav, Jain”)
#$SPFieldUserValuereplacewith = New-Object Microsoft.SharePoint.SPFieldUserValue($SPWeb,10, “#Rink, Jain”)
#$ListItem[“Author”] = $SPFieldUserValue
$SPFieldUserValueOriginalCreatedby = $ListItem[“Author”]
$SPFieldUserValueOriginalModifiedby = $ListItem[“Editor”]
if ($SPFieldUserValueOriginalCreatedby -eq “18;#Name, Surname” -or $SPFieldUserValueOriginalModifiedby -eq “18;#Name, Surname”)
{
Write-Host $SPFieldUserValueOriginalCreatedby
Write-Host $SPFieldUserValueOriginalModifiedby
if ($SPFieldUserValueOriginalCreatedby -eq “18;#Name, Surname”)
# “ID,#User Name” – ID from –>http://server/sites/EMEA1/_layouts/userdisp.aspx?ID=18
{
$ListItem[“Author”] = “69;#Vaibhav, jain”
Write-Host “found created by”
}else
{
$ListItem[“Author”]=$ListItem[“Author”]
}
# Note: Editor will be the account that you are running the Powershell under unless you update # Editor as well
# $ListItem[“Editor”] = $SPFieldUserValuereplacewith
if ($SPFieldUserValueOriginalModifiedby -eq “18;#Name, Surname”)
{
$ListItem[“Editor”] = “69;#Vaibhav, Jain”
Write-Host “found Modified by”
}else
{
$ListItem[“Editor”]=$ListItem[“Editor”]
}
$ListItem.Update()
}
}
}
$SPWeb.Update()
# Still TODO Disposes, Error Checking, Change to take Parameters, etc
Recent Comments