6

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?

10

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.

  • 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
1

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"
}
  • This really helped me out! :) Thanks! Very useful! – Nullldata Dec 1 '15 at 23:36
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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