PowerShell Script для обновления всех пользователей
-
09-12-2019 - |
Вопрос
Хорошо, я наполовину спите, что я сделал не так с моим скриптом 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.Но в моей соннонеме я прочитаю ошибку, а ключ был там, у меня не было разрешений учетной записи.
"Никакое приложение профиля пользователя доступно для обслуживания запроса« Я просто не видел эту ошибку, первые 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.