MIM – Finding users with certain changed attributes last 24 hours

This post contains a quick example on how to find users with certain attributes update the last 24 hours. The script uses the Lithnet PowerShell Module, which can be install using Install-Module LithnetRMA.

# Find all requests for person objects last 24 hours
$Requests = Search-Resources "/Request[Target = /Person and RequestStatus = 'Completed' and CreatedTime > op:subtract-dayTimeDuration-from-dateTime(fn:current-dateTime(), xs:dayTimeDuration('P1D'))]" -AttributesToGet RequestParameter, Target

# Define attributes
$attributes = @("Email";"AccountName")

# Filter out relevant requests
$RelevantRequests = $Requests | Where RequestParameter | Where {
    # Write-Verbose $_.objectid.value -verbose
    $_.RequestParameter | Where {
        $RequestParameter = [xml] $_
        $RequestParameter.RequestParameter | ? PropertyName -in $attributes
    }    
}

# Filter out each relevant change (ObjectID and ChangedAttribute)
$RelevantChanges = $RelevantRequests | Foreach {
    $Target = $_.Target
    $_.RequestParameter | Foreach {
        $RequestParameter = [xml] $_
        foreach($attribute in $attributes) {
            $RequestParameter.RequestParameter | ? PropertyName -eq $attribute | Foreach {[PSCustomObject]@{ObjectID = $Target.Value; ChangedAttribute = $attribute}}
        }
    }
}

$RelevantChanges | Out-GridView

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s