好的,我半睡半醒,我的powershell脚本做错了(用我修改了我刚刚想到了一个团队)

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()
    }
}
.

[编辑]抱歉塔托斯我以为我已经包括那个,不知道发生了什么:

配置文件变量从ProfileManager返回NULL。但在我睡眠中,我读了错误,线索在那里,我没有帐户权限。

“没有用户配置文件可供服务请求”我只是没有看到此错误运行脚本的前50次。

完成。

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
scroll top