Question

Okay I am half asleep, what did I do wrong with my powershell script (modified with I have just watched the A-Team in mind)

function update-fields () {
#Set up default variables

#My Site URL
$mySiteUrl = "http://cia-central"

#Get site objects and connect to User Profile Manager service
$site = Get-SPSite $mySiteUrl
$context = Get-SPServiceContext $site
$profileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context) 
$profiles = $profileManager.GetEnumerator()

    foreach ($up in $profiles) {
        Write-Host $up["UserName"].Value
        $firstname = $up["UserName"].Value
        $up["FirstName"].Value = $firstname
        $up["LastName"].Value = "Lynch"
        $up["Role"].Value = "Operative"
        $up["Entity"].Value = "CIA"
        $up["WorkPhone"].Value = "01234 568 901"
        $up["EMail"].Value = $firstname + ".lynch@cia.com"
        $up.Commit()
    }
}

[Edit] Sorry thantos I thought I had included that, don't know what happened:

The profiles variable is coming back NULL from the profilemanager. But in my sleepyness I re read the error and the clue was there, I didn't have the account permissions.

"No user profile application available to service the request" I just didn't see this error the first 50 times running the script.

Done.

Was it helpful?

Solution

The profiles variable is coming back NULL from the profilemanager. But in my sleepyness I re read the error and the clue was there, I didn't have the account permissions.

"No user profile application available to service the request" I just didn't see this error the first 50 times running the script.

Done.

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top