使用PowerShell更新SharePoint 2010 UserProfile Service的Property value

今天在一台SharePoint2010 Server上修改UserProfile的属性值本来打算写代码进行update的,但是测试不是太方便,就直接用PowerShell脚本进行修改了。

Step 1:在Power Shell中导入SharePoint的Assembly,Add-PSSnapin的功能就像java的Import语句一样,可以用来导入第三方的GAC

#import SharePoint Assembly
Add-PSSnapin Microsoft.SharePoint.PowerShell -EA SilentlyContinue 

Step 2:通过Get-SPServiceContext获取SPServiceContext对象,并将context的对象作为new UserProfileManager 实例的参数,有了UserProfileManger对象实例之后,可以通过GetUserProfile(loginname)的方法来获取需要修改的UserProfile对象。如果有多个对象,我们可以将对象写在CSV文件中,每个loginname占一行,然后用"$userlist=Import-Csv -Path $path"语句将需要修改的userprofile信息读入变量$userlist中,再通过Foreach进行循环就可以了。
#get SPServiceContext object, UserProfileManager object and UserProfile object
$context=Get-SPServiceContext -Site "http://sitecollections"
$upm=New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context)
$profile=$upm.GetUserProfile("domain\userid")

Step 3:修改userprofile property的语句如下,不要忘记修改好之后Commit。
#set value of userprofile property
$profile["user profile property"].value="value"
$profile.Commit()


注意:如果userprofile的property设置了“Pick a Term Set for this property”,那就要注意了,你的复制必须是Meta data service中指定Term Set中存在的值,否则会报错。

Step 4:获取userprofile property的语句。
#get value of userprofile property
$prop=$profile["user profile property"].value.ToString();


reference: SharePoint 2010: Updating User Profile Properties with PowerShell

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值