PoshCode Archive  Artifact [2f635601b3]

Artifact 2f635601b3adc4199ec6d88484dff8283cbc0d6ae5912761865c8f7bd365740e:

  • File Get-MOSS-User-Profile.ps1 — part of check-in [4b101b2957] at 2018-06-10 12:56:50 on branch trunk — Quick functions to get either (user: Peter size: 1927)

# 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"



#