Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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()
share|improve this question

1 Answer 1

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.

share|improve this answer
    
but I cannot find Microsoft.Office.Server.UserProfiles in my ISAPI dll's / –  RHM Apr 3 '13 at 11:14
    
What version of SharePoint do you have? –  Alexander Apr 3 '13 at 11:50
    
SharePoint Foundation 2010 –  RHM Apr 3 '13 at 11:58
    
I found this –  Alexander Apr 3 '13 at 12:13
    
hmmm so its not available in Foundation version –  RHM Apr 3 '13 at 12:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.