1

I am using the following Powershell script for updating User Information List in SP2013 environment. I am a member of Administrators group and also Site collection administrator.

$Site = Get-SPSite "https://www.something.com"
$web = $Site.RootWeb

$list = $web.Lists["User Information List"]
$query = New-Object Microsoft.SharePoint.SPQuery
$query.Query = "<Where><Contains><FieldRef Name='Name' /><Value Type='Text'>[email protected]</Value></Contains></Where>"
foreach ($item in $list.GetItems($query)) 
{
    $item["Department"] = "Marketing Department"
    $item.SystemUpdate()  

    "Name = " + $item["Name"] + " :: Department = " + $item["Department"]
}

The script is running successfully on DEV and TEST environments. But on my production environment i am getting following error for $item.SystemUpdate() statement,

Exception calling "SystemUpdate" with "0" argument(s): "0x80070005" At D:\Solution\UserProfileUpdation\testscript.ps1:12 char:9 + $item.SystemUpdate() + ~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : UnauthorizedAccessException

4
  • Amit Tyagi: The exception clearly says UnauthorizedAccessException. Are you able to manually modify the list from the Browser using the same account? Dec 31, 2014 at 23:07
  • @AmalHashim Actually i am not able to login using the account i am using with Powershell. The account i am using for powershell is my AD account. But we have ADFS only authentication on our SP2013 farm and i use my account from different AD via a authentication provider to login to SharePoint.
    – Amit Tyagi
    Dec 31, 2014 at 23:22
  • Were you able to resolve this problem? I am facing same issue as well.
    – xs2mayank
    May 4, 2016 at 11:55
  • Nope...sorry somebody else from my team took this over and i was dragged into something else. So, no update on this. I am not even working for that organization now.
    – Amit Tyagi
    May 4, 2016 at 18:59

2 Answers 2

2

Obviously I am late to this party... But I wanted to figure this out as I needed it for a domain migration that was having some issues, I believe as it was pointed out the main problem for @Amit Tyagi was a permissions issue, I edited his code above and ran it with the SharePoint Farm Administrator account that had local Administrator privileges below is the code that worked for me:

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

$Site = Get-SPSite "http://yourURLgoesHERE"
$web = $Site.RootWeb

$list = $web.Lists["User Information List"]

$i = $list.Items | where {$_["Account"] -eq "i:0#.w|yourDOMAINhere\USERidHERE"}

#$query = New-Object Microsoft.SharePoint.SPQuery
#$query.Query = "<Where><Contains><FieldRef Name='Name' /><Value Type='Text'>[email protected]</Value></Contains></Where>"
foreach ($item in $i) #$list.GetItems($query)) 
{
    $item["Department"] = "Marketing Department"
    $item["JobTitle"]   = "Administrative Assistant"
    $item.SystemUpdate()  

    Write-Host "Account = " + $item["Account"] + "was updated :: Department = " + $item["Department"] + " :: Job Title = " + $item["JobTitle"] 

As I said this code worked for me, I did not match on the email but rather the user account is the only difference in the code.

Assuming there is not an issue with the UPSa and the UIL sync job this information should get updated going forward if the user account has any changes made to it.

Here is a bonus, some columns that are in the UIL ("User Information List")

enter image description here

0

Try checking ULS for more detailed logs of the error

I have seen cases where the exception message is not very helpful.
Actually it was the sharepoint_config database that had filled the disk with transaction logs.
After backup/shrink of transaction log everything worked fine

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.