3

I have a problem when loading a UserProfile from the UserProfileService in Powershell. I am able to get a list of properties, however I can't seem to find when the profile was last modified.

One property that appears close is CurrentChangeToken however for all of my user profiles it is 1;28208;03/18/2014 02:00:00 which is a few hours before I ran the script.

$siteUrl = "http://intranet/"
$site = Get-SPSite $siteUrl
$context = Get-SPServiceContext($site)
$pm = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context)

$allUsers = Get-SPUser -Web $siteUrl
$allUsers = $allUsers | Where-Object { $_.UserLogin -like "*DOMAIN*" }
$resultsArray =@()

foreach($user in $allUsers)
{    
    if($pm.UserExists($user.UserLogin))
    {
        $userProfile = $pm.GetUserProfile($user.UserLogin)
    }
}

Does anyone know how I can get the last modified date of each User Profile?

3 Answers 3

1

We can find the profile modified date by using LastContentModifiedDate userprofile property. Please check the same property in the PowerShell code.

Here is sample code in server object model:

using (SPSite site = new SPSite("siteurl"))
{                       
    SPServiceContext context = SPServiceContext.GetContext(site);
    UserProfileManager profileManager = new UserProfileManager(context);
    foreach (var profile in profileManager)
    {
        userName = ((Microsoft.Office.Server.UserProfiles.UserProfile) (profile)).AccountName.ToString().Split('\\')[1];

        if ((((Microsoft.Office.Server.UserProfiles.UserProfile)(profile)).PersonalSite != null))
        {
            DateTime profileModifiedDate = ((Microsoft.Office.Server.UserProfiles.UserProfile)(profile)).PersonalSite.LastContentModifiedDate;
        }
    }
}
1

Personal Site just returns the MySite of the user. It does not help you retrieve the User Profile information. Please check in FIM (missclient), there you have a lot of info.

1

I needed something like this to list the last date the user changed the profile. I created this script using info i found on the internet including this page so thanks everyone ;-).

$siteUrl = "http://profilesite/"
$site = Get-SPSite $siteUrl
$context = Get-SPServiceContext($site)
$pm = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context)
$changes = $pm.GetChanges()
$result = @{}
$count = 0
foreach($change in $changes)
{
    if($result.ContainsKey($change.accountname))
    {
        $result.Set_Item($change.accountname,$change.eventtime)
    }
    else
    {
        $result.add($change.accountname , $change.eventtime)
    }
    $count = $count + 1
}
$result
$count

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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