Script PowerShell per aggiornare tutti gli utenti
-
09-12-2019 - |
Domanda
Okay ho dormito a metà, cosa ho fatto di sbagliato con il mio script di PowerShell (modificato con Ho appena visto la squadra A-team)
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()
}
}
.
[modifica] Scusa Thantos Ho pensato di aver incluso, non sai cosa è successo:
La variabile dei profili sta tornando NULL DAL PROFILEMAAGER.Ma nella mia assonnata, ho letto l'errore e l'indizio era lì, non avevo le autorizzazioni dell'account.
"Nessuna applicazione del profilo utente disponibile per il servizio della richiesta" Non ho visto questo errore i primi 50 volte in esecuzione lo script.
Fatto.
Soluzione
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.