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