使用PowerShell更改sharepoint 2010中所有用户的用户配置文件属性

时间:2015-05-28 03:55:39

标签: powershell sharepoint-2010

我想更改所有用户名为Department的用户个人资料属性的编辑设置和显示设置值。有人可以告诉我该怎么做。

我可以使用此PowerShell访问department属性。现在这个属性编辑设置是不允许用户编辑这个属性,我想让它为每个用户编辑。

Add-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue
$mySiteUrl = "http://www.test.com/mysite"
$site = Get-SPSite $mySiteUrl
$context = Get-SPServiceContext $site
$profileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context)
$userProfile = $profileManager.GetUserProfile("Test\822");
$userProfile.Properties | sort DisplayName | FT DisplayName,Name,@{Label="Type";Expression={$_.CoreProperty.Type}}
$userProfile["Department"].Value 
$site.Dispose()

由于

1 个答案:

答案 0 :(得分:0)

我猜你的意思是这个属性,对吧?

enter image description here

以下脚本演示了如何设置IsUserEditable用户个人资料属性的Departments子属性:

if ((Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null)
{
    Add-PsSnapin Microsoft.SharePoint.PowerShell
}


$siteUrl = "http://contoso.intranet.com/"

$site = Get-SPSite $siteUrl
$context = Get-SPServiceContext($site)


$profileConfigMgr = New-Object Microsoft.Office.Server.UserProfiles.UserProfileConfigManager($context) 
$profilePropMgr = $profileConfigMgr.ProfilePropertyManager
$subtypePropMgr = $profilePropMgr.GetProfileSubtypeProperties("UserProfile")
$subtypeProp = $subtypePropMgr.GetPropertyByName("Department")
$subtypeProp.IsUserEditable = $true
$subtypeProp.Commit()

<强>参考

How to: Work with user profiles and organization profiles by using the server object model in SharePoint 2013