I am using SP2013 and trying to update the “Author” and “Editor” properties of a folder in a document library. When I run my script it appears that it updates the fields correctly, however, when I check the values again they are not actually modified. I am not sure why … Here is my existing script.
$web = Get-SPWeb “http://mytestbox/sites/tech/”
$site=$web
$list = $web.Lists[“Reports”]
foreach ($item in $list.Folders)
{
$itemauthor = $item[“Author”]
$itemeditor = $item[“Editor”]
$itemmod = $item.Properties.vti_modifiedby
write-host “Author is: ” $itemauthor
write-host “Editor is: ” $itemeditor
write-host “Modified By is: ” $itemmod
if($itemauthor -eq “1;#domainxyz\doveal”)
{
$itemauthor = “1;#sharepoint\system”
Write-Host “The folder author is ” $itemauthor
$item.Update()
Write-Host “The folder author is updated”
}
if($itemeditor -eq “1;#domainxyz\doveal”)
{
$itemeditor = “1;#sharepoint\system”
Write-Host “The folder editor is ” $itemeditor
$item.Update()
Write-Host “The folder editor is updated”
}
if($itemmod -eq “i:0#.w|domainxyz\doveal”)
{
$itemmod = “i:0#.w|sharepoint\system”
Write-Host “The folder modified by is ” $itemmod
$item.Update()
Write-Host “The folder modified by is updated”
}
write-host “Author is: ” $itemauthor
write-host “Editor is: ” $itemeditor
write-host “Modified By is: ” $itemmod
}
$site.Update()
$site.Dispose()
Â
Hi Alex
use this code:
$inputUrl = Read-Host “Enter the site URL”
$libName = Read-Host “Enter list or library name”
$web = Get-SPWeb -Identity $inputUrl
$list = $web.Lists[“$libName”]
[Microsoft.SharePoint.SPUser]$user = $web.EnsureUser(“<LoginName of the User>”)
#$user = Get-SPUser -identity “q3tech\sp_farm” -web $web
foreach ($item in $list.folders)
{
$item[“Editor”] = $user
$item.Update()
}
$web.Dispose
Here I have used Jason code with only one change.
I have replacedÂ
$user = Get-SPUser -identity “SHAREPOINT\system” -web “<someSPWeb>”
withÂ
[Microsoft.SharePoint.SPUser]$user = $web.EnsureUser(“SHAREPOINT\system”)
and it works fine now