User Profile
SharePoint 2010 change order of User Profile properties
SharePoint 2010 Mass Uploading profile pictures programatically
SharePoint 2010 PowerShell to create a new User Profile Property
http://gallery.technet.microsoft.com/office/SP2010-PowerShell-to-0fda04f7 (Had some issues with this script.)
http://therelentlessfrontend.com/2012/03/20/powershell-script-to-add-a-user-profile-property-and-synch-it-with-an-active-directory-property-in-sharepoint-2010/ (This one worked for me.)
I did couple of modifications to fit my needs:
1) Creating several properties using a CSV containing the property info
2) I have only tested for string and integer properties.
param($CSVFile)
Clear-Host
$ver = $host | select version
if ($ver.Version.Major -gt 1) {$host.Runspace.ThreadOptions = “ReuseThread”}
if ((Get-PSSnapin “Microsoft.SharePoint.PowerShell” -ErrorAction SilentlyContinue) -eq $null)
{
Add-PSSnapin “Microsoft.SharePoint.PowerShell”
}
#Load SharePoint User Profile assemblies
[System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.SharePoint”)
[System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.Office.Server”)
[System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.Office.Server.UserProfiles”)
[System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.SharePoint.Administration”)
#Function to get service context
function Get-SPServiceContext([Microsoft.SharePoint.Administration.SPServiceApplication]$profileApp)
{
$profileApp = @(Get-SPServiceApplication | ?{$_.TypeName -eq “User Profile Service Application”})[0]
#$profileApp = Get-SPServiceApplication | where {$_.DisplayName -eq “User Profile Service Application”}
return [Microsoft.SharePoint.SPServiceContext]::GetContext($profileApp.ServiceApplicationProxyGroup,[Microsoft.SharePoint.SPSiteSubscriptionIdentifier]::Default)
}
#Get UserProfileManager
$serviceContext = Get-SPServiceContext
$userProfileConfigManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileConfigManager($serviceContext)
$userProfilePropertyManager = $userProfileConfigManager.ProfilePropertyManager
$userProfilePropertyManager = $userProfilePropertyManager.GetCoreProperties()
$userProfileTypeProperties = $userProfileConfigManager.ProfilePropertyManager.GetProfileTypeProperties([Microsoft.Office.Server.UserProfiles.ProfileType]::User)
$userProfileSubTypeManager = [Microsoft.Office.Server.UserProfiles.ProfileSubTypeManager]::Get($serviceContext)
$userProfile = $userProfileSubTypeManager.GetProfileSubtype([Microsoft.Office.Server.UserProfiles.ProfileSubtypeManager]::GetDefaultProfileName([Microsoft.Office.Server.UserProfiles.ProfileType]::User))
$userProfileProperties = $userProfile.Properties
Import-Csv $CSVFile |foreach {
#PropertyName,PropertyDisplayName,Privacy,PrivacyPolicy,CorePropertyType,CorePropertyLength,IsVisibleOnEditor,IsVisibleOnViewer,IsEventLog
#Set Custom Property values
$PropertyName = $_.PropertyName
$PropertyDisplayName = $_.PropertyDisplayName
#The possible enumeration values are “Private [Only Me], Manager [Me and my manager], My Workgroup [Organization], My Colleagues [Contacts], Public [Everyone]”
$Privacy=$_.Privacy
#The possible enumeration values are “Mandatory, OptIn, OptOut, Disabled”
$PrivacyPolicy=$_.PrivacyPolicy
$coreProperty = $userProfilePropertyManager.Create($false)
$coreProperty.Name = $PropertyName
$coreProperty.DisplayName = $PropertyDisplayName
$coreProperty.Type = $_.CorePropertyType
#Write-Host $coreProperty.Type
if($coreProperty.Type -eq “string (Single Value)”)
{
$coreProperty.Length = $_.CorePropertyLength
}
#Add Custom Property
$userProfilePropertyManager.Add($coreProperty)
$profileTypeProperty = $userProfileTypeProperties.Create($coreProperty)
#Display Settings
#Show on the Edit Details page
$profileTypeProperty.IsVisibleOnEditor = $_.IsVisibleOnEditor
#Show in the profile properties section of the user’s profile page
$profileTypeProperty.IsVisibleOnViewer = $_.IsVisibleOnViewer
#Show updates to the property in newsfeed
$profileTypeProperty.IsEventLog = $_.IsEventLog
$userProfileTypeProperties.Add($profileTypeProperty)
$profileSubTypeProperty = $userProfileProperties.Create($profileTypeProperty)
$profileSubTypeProperty.DefaultPrivacy =[Microsoft.Office.Server.UserProfiles.Privacy]::$Privacy
$profileSubTypeProperty.PrivacyPolicy = [Microsoft.Office.Server.UserProfiles.PrivacyPolicy]::$PrivacyPolicy
$userProfileProperties.Add($profileSubTypeProperty)
Write-Host -f Blue “Property ” + $PropertyName + ” is created successfully”
}
CSV File format:
PropertyName,PropertyDisplayName,Privacy,PrivacyPolicy,CorePropertyType,CorePropertyLength,IsVisibleOnEditor,IsVisibleOnViewer,IsEventLog
DistrictID3,District ID 3,Public,OptIn,integer,NULL,FALSE,FALSE,FALSE
DistrictName3,District Name 3,Public,OptIn,string,50,FALSE,FALSE,FALSE