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

The following script spits out all UserProfile properties for users on Sharepoint 2007:

[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server.UserProfiles")
# Function:          Get-UserProfiles
# Description:       return a UserProfileManager object containing all user profiles
# Parameters:        SSPName          SSPName    
#
Function global:Get-UserProfiles($SSPName)
{
    $ServerContext = [Microsoft.Office.Server.ServerContext]::GetContext($SSPName);
    $UPManager = new-object Microsoft.Office.Server.UserProfiles.UserProfileManager($ServerContext);
    return $UPManager.GetEnumerator();
}

$profiles = Get-UserProfiles("SharedServices");
$profiles | ForEach-Object { $_.GetEnumerator();}

However, what I want to do is be able to return a table, or csv file of specific values in the profile, e.g. Username, WorkEmail, WorkPhone. I have tried piping the output to |ft Username, WorkEmail, Workphone and | select Username, WorkEmail, WorkPhone but this just returns blanks.

I feel like I am so close. I don't want to replace the $_.GetEnumerator() call with lots of $_.Item("property") calls and it doesn't feel like I should have to. Any ideas?

share|improve this question
add comment

3 Answers

up vote 7 down vote accepted

This is a pretty old thread so you've probably already figured this out but for the sake of helping to close it out, here's one way you could solve the problem (there are others):

$profiles | ForEach-Object { 
    $vals = $_.GetEnumerator();
    $hash = @{};
    foreach ($val in $vals) {
        $hash[$val.Key] = $val.Value
    }
    New-Object PSObject -Property $hash
} | Out-GridView

You can replace the Out-GridView call with Export-Csv to create a CSV file.

share|improve this answer
    
I like this approach. The only thing I can see is that is does not handle multivalue properties. I have several multivalue properties that are mapped to term-sets. How is it possible to show these? –  Kjaps Jun 4 '12 at 21:43
add comment

Another solution to loop all profiles can be found on my blog http://www.n8d.at/blog/sharepoint-2010/clean-up-user-profile-store/

I used to iterate over all user profiles to delete them.

share|improve this answer
add comment

Another solution to iterate through the User Profiles is also posted on blog:

$url = "http://sharepointserver/"
$site = Get-SPSite $url
$context = Get-SPServiceContext $site
$profileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context)
$profiles = $profileManager.GetEnumerator()

while ($profiles.MoveNext()) {
  $userProfile = $profiles.Current
  $name = $userProfile.DisplayName
  $myprop= $userProfile["MypropertyName"]
  Write-Host "$name;$myprop"
}
share|improve this answer
add comment

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.