Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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.

share|improve this question
    
Could you please provide more information? What is it doing or not doing? –  thantos Aug 27 '12 at 16:44
add comment

1 Answer 1

up vote 0 down vote accepted

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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