This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

onPostModify Function

I'm writing a post modify PS function that updates the email address. I only want it to run if the first or last name is modified.

How do I tell within the $request what attribute was modified so I can stop the function if it wasn't first or last name?

 

Thank you.

  • I strongly recommend to look at ARS SDK (contains sample code) look at other legacy forums.
    here is example:
    --------------
    function onPreModify($Request)
    {
    if ($request.Class -ne "user") {return}

    if (IsAttributeModified "desriptiopn" $Request) {
    #If AD\user.description is modified do action here
    }
    }
    # IsAttributeModified
    function IsAttributeModified([string]$attr,$Request)
    {
    [bool]$Modified = $False
    if($Request -ne $null)
    {
    $Item = $Request.GetPropertyItem($attr,0)
    if($Item -ne $null)
    {
    if($Item.ControlCode -ne 0) { $Modified = $true }
    }
    }
    return $Modified
    }
  • Couple of options:

    You can trap that specific attribute change with an ActiveRoles workflow start condition and then trigger your script that way.

    OR

    Your script can look at the $Request - it will tell you which attribute was changed. There is a library script available (free) from Quest that can help you to interrogate the $Request object for the modified attributes.
  • Thank you both of you. Yes I have looked thru the SDK. I'll do some modifications to my code to see what I can accomplish.

    I'll have a look the workflows, we don't use those but I might be able to use them for this type of stuff.
  • The workflow start conditions in particular can save you a lot of coding when it comes to trapping events.

    The nice thing about them too is that unlike script policies, you are not tied to a provisioning policy - this offers additional flexibility because you can have your scripts triggered in many different ways.

    Workflows in general are a very powerful technology within the product.