0

I've trying to iterate each User Profile with this snippet but at the following step:

write-host "Job Description for user" $User " is : " $up[$upAttribute].Value

the code always return the SuperUSer AccountName

$mySiteUrl = "http://MYsite"
#$adAccount = "DOMAIN\chill"
$upAttribute = "AccountName"
#$upAttributeValue = “http://get-spscripts.com”

#Get site objects and connect to User Profile Manager service
$site = Get-SPSite $mySiteUrl
$context = Get-SPServiceContext $site
$profileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context)




function GetSPWebUsers($mySiteUrl) 
{ 
    [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") > $null 
    $site = new-object Microsoft.SharePoint.SPSite($mySiteUrl) 
    $web = $site.openweb() 
    $siteUsers = $web.SiteUsers 

    foreach($user in $siteUsers) 
    {        

        GetUserProfile($user)
        #if($user.IsSiteAdmin -eq $true) 
       # { 
           # Write-Host "ADMIN: ", $user.LoginName 
        #} 
       # else 
       # {  
           # Write-Host "USER: ", $user.LoginName 
        #} 
       # Write-Host " ------------------------------------- " 
    }    
    $web.Dispose() 
    $site.Dispose() 
} 



function GetUserProfile($User)
{ 


#Check to see if user profile exists
if ($profileManager.UserExists($User))
{
    #Get user profile and change the value
    $up = $profileManager.GetUserProfile($User)
    if(($up[$upAttribute].Value  -ne $null))
    {  

        Write-Host "Site Collection URL:", $mySiteUrl 
        write-host "Job Description for user" $User " is : " $up[$upAttribute].Value 
        Write-Host " ------------------------------------- "  

     }
     else
      {  
          #write-host "Job Description for user" $User
      }

   # $up.Commit()
}
else
{
   # write-host "Profile for user"$User "cannot be found"
}
#Dispose of site object
$site.Dispose()
}

user DOMAIN\21000045 is : DOMAIN\mossadm

user DOMAIN\00006244 is : DOMAIN\mossadm

user DOMAIN\00003613 is : DOMAIN\mossadm

user DOMAIN\00000538 is : DOMAIN\mossadm

user DOMAIN\21002202 is : DOMAIN\mossadm

1

1 Answer 1

0

None of the prototypes of UserProfileManager.GetUserProfile take SPUser object as a parameter.

So, you may need to slightly modify your code:

Replace this code:

    $up = $profileManager.GetUserProfile($User)

With:

    $up = $profileManager.GetUserProfile($User.UserLogin)

Your Answer

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

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