用powershell更新user的display name

同理可以更新任何其他信息: 

$WebUrl = "http://yourwebsiteurl"       

$OpenWeb = Get-SPWeb $WebUrl

 

$site = new-object Microsoft.SharePoint.SPSite($WebUrl); 

$ServiceContext = [Microsoft.SharePoint.SPServiceContext]::GetContext($site); 

 

#Get UserProfileManager from the My Site Host Site context

$ProfileManager = new-object Microsoft.Office.Server.UserProfiles.UserProfileManager($ServiceContext) 

$AllProfiles = $ProfileManager.GetEnumerator() 

 

foreach($profile in $AllProfiles) 

    $DisplayName = $profile.DisplayName 

    $AccountName = $profile[[Microsoft.Office.Server.UserProfiles.PropertyConstants]::AccountName].Value 

    

     $claim =New-SPClaimsPrincipal $AccountName  -IdentityType WindowsSamAccountname

     $user = Get-SPUser -web $WebUrl  -Identity $claim

     $user.DisplayName=$DisplayName

     $user.Update()    

}

posted @ 2012-09-12 21:28  举重-若轻  阅读(280)  评论(0)    收藏  举报