# encoding: ascii
# api: powershell
# title: Get MOSS User Profile
# description: Quick functions to get either
# version: 0.1
# type: function
# author: Peter
# license: CC0
# function: Get-UserProfile
# x-poshcode-id: 1306
# x-archived: 2014-06-01T17:09:51
# x-published: 2010-09-03T15:04:00
#
# a) the raw UserProfile object, which you may use to quickly inspect or modify;
# b) a more user-friendly display of the object data. Because there are no bulk methods to grab user profile data, this may be used to effectively extract your user profile data.
# Side note: beware, enumerating over the UserProfileManager object is SLOW.
# Assumption: haven’t tested against multi-value properties, so I’m not sure how they look.
#
function Get-UserProfile($accountName)
{
[reflection.assembly]::LoadWithPartialName("Microsoft.SharePoint") | out-null
[reflection.assembly]::LoadWithPartialName("Microsoft.Office.Server") | out-null
$upm =[Microsoft.Office.Server.UserProfiles.UserProfileManager](
[Microsoft.Office.Server.ServerContext]::Default)
$upm.GetUserProfile($accountName)
}
function Get-UserProfileData($profile)
{
$propsToDisplay = $upm.Properties | ? { $_.IsSystem -eq $false -and $_.IsSection -eq $false }
$o = new-object PSObject
$propsToDisplay | foreach {
add-member -inp $o -membertype NoteProperty -name $_.Name -value $profile[$_.Name].Value
}
$o
}
#USAGE 1: (update one profile)
# $up = Get-UserProfile "spadmin"
# $up["YourCustomField"].Value = "new value"
# $up.Commit()
#
#USAGE 2: (export profile data to CSV)
#
# $upm = [Microsoft.Office.Server.UserProfiles.UserProfileManager](
# [Microsoft.Office.Server.ServerContext]::Default)
# $unrolledProfilesCollection = $upm | foreach { $_ }
# $unrolledProfilesCollection | foreach { Get-UserProfileData $_ } | export-csv -NoTypeInformation "C:\temp\profiles.txt"
#