2

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()

1 Answer 1

0

Try to use Add-Type cmdlet

The Add-Type cmdlet lets you define a .NET Framework class in your Windows PowerShell session. You can then instantiate objects (by using the New-Object cmdlet) and use the objects, just as you would use any .NET Framework object. If you add an Add-Type command to your Windows PowerShell profile, the class will be available in all Windows PowerShell sessions.

See full description here.

5
  • but I cannot find Microsoft.Office.Server.UserProfiles in my ISAPI dll's / Commented Apr 3, 2013 at 11:14
  • What version of SharePoint do you have? Commented Apr 3, 2013 at 11:50
  • SharePoint Foundation 2010 Commented Apr 3, 2013 at 11:58
  • I found this Commented Apr 3, 2013 at 12:13
  • 1
    hmmm so its not available in Foundation version Commented Apr 3, 2013 at 12:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.