首页 > 代码库 > 根据XML更新Userprofile
根据XML更新Userprofile
# Using powershell code, update the user profile base on the XML file.
# Date: 2015-01-29
# Update New User Property$snapin = Get-PSSnapin | Where-Object {$_.Name -eq ‘Microsoft.SharePoint.Powershell‘} if ($snapin -eq $null) { Write-Host "Loading SharePoint Powershell Snapin..." Add-PSSnapin "Microsoft.SharePoint.Powershell" Write-Host "SharePoint Powershell Snapin Loaded" }# Get XML Configuration file[xml]$xmlData=Get-Content "C:\xxxx\xxxx.xml" -Encoding UTF8# Get Connection to MySite $MySite = Get-SPSite -Identity "http://xxxxxx"# Get Context$context = Get-SPServiceContext($MySite) # Get UserProfileManager Object$ProfileMngr = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context) # Get All User Profiles#$profiles = $ProfileMngr.GetEnumerator()$xmlData.Users.UserName | ForEach-Object{ if ($ProfileMngr.UserExists($_.Name) -eq $false){ $ProfileMngr.CreateUserProfile($_.Name) } $userprofile = $ProfileMngr.GetUserProfile($_.Name) $userprofile["DP-JobNo"].value = http://www.mamicode.com/$_.JobNo.Name $userprofile["PreferredName"].value = http://www.mamicode.com/$_.PreferredName.Name $userprofile["DP-CompanyCode"].value = http://www.mamicode.com/$_.CompanyCode.Name $userprofile["DP-Company"].value = http://www.mamicode.com/$_.Company.Name $userprofile["DP-Department"].value = http://www.mamicode.com/$_.Department.Name $userprofile["DP-ReportToLeader"].value = http://www.mamicode.com/$_.ReportTo.Name $userprofile["DP-CostCentre"].value = http://www.mamicode.com/$_.CostCentre.Name $userprofile.Commit() Write-Host -f Yellow $_.Name "Done" }
<User Name="xx\xx"> <Chinese Name="xxx"/> <Title Name=""/> <CostCenter Name="xxx"/> <Report Name="xxxxx"/> <Company Name="xxxx"/> <Bank Name="xxxxxx"/> <Internal Name=""/> <Sap Name=""/> <IsSales Name="False"/> <IsService Name="False"/></User>
根据XML更新Userprofile
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。