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

Need to find out all attributed modified in function onPreModify

Hi all!

I need to dynamically find all attributes modified in function onPreModify($Request).

I do NOT want to something like:

function onPreModify($Request)

{

if ((IsAttributeModified "edsva_myattribute" $Request) -eq $true)

        {
            #do something like mail info someone that a attribute "edsva_myattribute" changed for a certain user to a certain value
        }

}

 

rather I like to have:

function onPreModify($Request)

{

$attributeschanged = $request.thefuntionIlookfor() #give me a list all attributes changed 

foreach($attribute in $attrubuteschanged)

{
 
#do something like mail info someone these these x number of attributes changed for a certain user and the new values was x,z,y

}

Cant find that scenario in articles, maybe someone else has?

Best regards,

//Johan Salomonsson

  • What I have done in the past is created a loop to check the properties I am looking for changes to and if they are changed, store them in array for subsequent processing through another loop that "Switches" based on attribute name:

    $KeyProps = "Attrib1","Attrib2","Attrib3"

    foreach ($PropItem in $KeyProps)
    {

    # If the attribute has been changed, add it to the processing queue

    # Checks the current ActiveRoles transaction ($Request) to see if the attribute
    # is being processed by it

    if ((IsAttributeModified $PropItem $Request))
    {
    $AttributeProcessingQueue += $PropItem
    }

    } # End of properties scan loop

    $AttributeProcessingQueue | %{

    $CurrentQueueItem = $_

    Switch ($CurrentQueueItem){

    Attrib1 {#Do something}
    Attrib2 {#Do something else}
    Attrib3 {#Do something else still}

    } # End of Property name switch

    } # End of property loop

     

    You could probably skip building up the queue and do this all in one loop but I thought that for instructional purposes, this code is easier to follow.

  • Hi and thanks for the answer

    However, I would prefer not to specify any attributes that I am looking for because I want the function complete generic, I would like a way (function, property etc) to ask what properties has changed and go from there.

    Best regards,

    //Johan
  • Hi Johan,

    This can be accomplished using the following:

    function onPreModify($Request)
    {
        $Request.Attributes.Attributes | %{
            $_.Name | Out-File -FilePath "C:\Temp\AttributeNames.txt" -Append
        }
    }


    That will output all modified attribute names to the text file. Please modify it appropriately for your use case. I hope this helps.