I want to run the following script but getting the error "Unable to find type [Microsoft.Office.Server.UserProfiles.PropertyConstants]"
#Add SharePoint PowerShell SnapIn if not already added
if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) {
Add-PSSnapin "Microsoft.SharePoint.PowerShell"
}
$site = new-object Microsoft.SharePoint.SPSite("sitenamehere");
$ServiceContext = [Microsoft.SharePoint.SPServiceContext]::GetContext($site);
$ProfileManager = new-object Microsoft.Office.Server.UserProfiles.UserProfileManager($ServiceContext)
$AllProfiles = $ProfileManager.GetEnumerator()
foreach($profile in $AllProfiles)
{
$Title = $profile[[Microsoft.Office.Server.UserProfiles.PropertyConstants]::Title].Value
$AccountName= $profile[[Microsoft.Office.Server.UserProfiles.PropertyConstants]::AccountName].Value
$PreferredName = $profile[[Microsoft.Office.Server.UserProfiles.PropertyConstants]::PreferredName].Value
if( $PreferredName -ne "None" -and $Title -ne $null )
{
write-host "Profile: ", $PreferredName,"(",$Title,")"
$dName = $PreferredName + " (" + $Title + ")"
#you can add update your users displayname like below
# Set-SPUser -identity $AccountName -SyncFromAD -web siteURLhere
}
}
write-host "Finished."
$site.Dispose()