Powershell: Creating and updating profile property
Hi Friends,
I have recently create a user profile property using power shell commands. I am just sharing the code i used to create and then edit the properties like description, privacy settings, display settings etc of the property.
Code to add/edit:
I want to share some of the basic properties which you can edit while updating the property using Power shell.
Hope this information will be helpful.
Thanks for Time :)
I have recently create a user profile property using power shell commands. I am just sharing the code i used to create and then edit the properties like description, privacy settings, display settings etc of the property.
Code to add/edit:
if ((Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null )
{
Add-PsSnapin Microsoft.SharePoint.PowerShell
}
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
[System.Reflection.Assembly]::LoadWithPartialName("microsoft.sharepoint.portal")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server")
[System.Reflection.Assembly]::LoadWithPartialName("System.Web")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Taxonomy.dll")
function CheckNull($obj, $name)
{
if ($obj -eq $null)
{
Write-Host $name "is null" -ForegroundColor Red
return $true
}
return $false
}
$siteurl = "http://sp2010server/"
$site = Get-SPSite -Identity $siteurl -ErrorAction Stop
$ctx = [Microsoft.Office.Server.ServerContext]::GetContext($site)
$upm = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($ctx)
$upcm = New-Object Microsoft.Office.Server.UserProfiles.UserProfileConfigManager($ctx)
$comProp = $upm.Properties.Create($false)
$comProp.Name = "Company"
$comProp.DisplayName = "Company"
$comProp.Type = [Microsoft.Office.Server.UserProfiles.PropertyDataType]::StringSingleValue
$comProp.Length = 50
$comProp.PrivacyPolicy = [Microsoft.Office.Server.UserProfiles.PrivacyPolicy]::OptIn;
$comProp.DefaultPrivacy = [Microsoft.Office.Server.UserProfiles.Privacy]::Public;
$comProp.IsVisibleOnViewer = $true;
$upm.Properties.Add($comProp)
I want to share some of the basic properties which you can edit while updating the property using Power shell.
- [string] $displayname : used if we want to change the display name under Property Settings.
- [int] $length: used to edit "Length" of the property value again under Property Settings.
- [string] $description: used to edit "Description" of the property value again under User Description.
- PrivacyPolicy: used to edit "Policy Settings" of the property value under Policy Settings.
- DefaultPrivacy: used to edit "Default Policy Settings"of the property value again under Policy Settings.
- [bool] $userOverridePrivacy: used to edit "User can override" of the property value again under Policy Settings.
- [bool] $isReplicable: used to edit "Replicable" of the property value again under Policy Settings.
- [bool] $isUserEditable: used to edit "Edit Settings" of the property
- [bool] $IsMultivalued: used to edit "Description" of the property value again under User Description.
- [bool] $isColleagueEventLog: used to edit "Show updates to the property in newsfeed" of the property value again under User Description.
- [bool] $isAlias: used to edit "Alias" of the property value under Search Settings.
- [bool] $isSearchable: used to edit "Indexed" of the property value again under Search Settings.
- [bool] $isVisibleOnEditor: used to edit "Show on the Editor Details Page" of the property value under Show Settings.
- [bool] $isVisibleOnViewer: used to edit "Show in the profile properties section of the user's profile page" of the property value again under Show Settings.
- [int] $maximumShown: used to edit "Show updates to the property in newsfeed" of the property value again under Show Settings.
Hope this information will be helpful.
Thanks for Time :)
Hey good post, but correct this :-)
ReplyDeleteisColleagueEventLog = used to edit “Show updates to the property in newsfeed” of the property value again under Show Settings
Thanks Ultranonymous :)... I modified the post content.
ReplyDeletedo you have any code to display/get/export all the existing profileproperty properties into a text file?
ReplyDeleteHi JH,
ReplyDeleteTo display and get all the profile properties please use the following code:
$siteurl = "http://sp2010server/"
$site = Get-SPSite -Identity $siteurl -ErrorAction Stop
$ctx = [Microsoft.Office.Server.ServerContext]::GetContext($site)
$upm = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($ctx)
$strLoginName=$web.CurrentUser.LoginName
$up=$upm.GetUserProfile($strLoginName)
$propertyColl=$up.ProfileManager.PropertiesWithSection
foreach($property in $propertyColl)
{
write-host $property.Name
}
Hope this will help you.
This will work for SharePoint Online..?
ReplyDeleteHi Ramesh,
ReplyDeleteI am sure it must work in Online as well, but didn't tested. May be you have to little bit tweak the authentication side in order to connect to Online. Let me know if I can help more.
Regards
Mohit
I am not certain the place you are getting your information, but
ReplyDeletegood topic. I must spend a while studying much more or figuring out
more. Thanks for excellent info I used to be looking for this info for my mission.
Hi,
ReplyDeleteI want to update the length of Custom user profile property but I am unable to do it..
Please help.
Thanks,
Rashmi