Copy additional attributes on user copy with Powershell script OnPostCreate?

Hi,

I have been trying to get additional attributes (description f.e.) when copy a user from Web Interface, but with $Request method on a Powershell script it's has been impossible to get the source object.

I finally used the VB scipt that is at the Wiki but I wondered if there is a way to do that with PowerShell.

I can see on the Windows Event Log for ARAdminSvc that when copy, its register the source object, but couldn't get the source object name from that neither.

Kind regards.

  • For identifying the source object, the key line of that script is this:

    Set SrcObj = rootDSE.OpenDSObject("EDMS://" & Request.GetInControl(EDS_CONTROL_SOURCE_OBJECT_DN), "", "", 0)

    The object name itself is coming from this part:  Request.GetInControl(EDS_CONTROL_SOURCE_OBJECT_DN)

    In Powershell, you could access this object like this:

    Try
    {
    $SourceObjectDN = $Request.GetInControl($Constants.EDS_CONTROL_SOURCE_OBJECT_DN)
    }
    Catch
    {
    }

  • #*********************************************************************************
    # THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
    # EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
    # WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
    #
    # IF YOU WANT THIS FUNCTIONALITY TO BE CONDITIONALLY SUPPORTED,
    # PLEASE CONTACT ONE IDENTITY PROFESSIONAL SERVICES.
    #*********************************************************************************
    
    #**************************************************************************
    # ATTRIBUTE TO COPY
    # Add/Remove Attributes as required
    #**************************************************************************
    $arrAttributeList = @("description", "company","l")
    
    #**************************************************************************
    # EVENT HANDLERS
    #**************************************************************************
    function onPostCreate($Request)
    {
        $Function = "OnPostCreate"
        
        #-- skip for another classes
        if ($Request.Class.ToLower() -ne "user".ToLower())
        {
            LogEvent -Message "$Function - Not user exiting" -Type "Info"
            return
        }
    
    
        #-- skip non copy requests
        if ([int]($Request.Parameter("Type")) -ne $Constants.EDST_REQ_COPY) 
        {
            LogEvent -Message "$Function - Not a copy operation" -Type "Info"
            return
        }
        #-- If the attributes list is empty, stop processing
        if($arrAttributeList.count -eq 0) 
        {
            LogEvent -Message "$Function - Attributes list is empty, exiting" -Type "Info"
            return
        }
    
        $srcObj = $null
        $Value = $null
        $rootDSE = $null
    
        #-- get source object
        if ([string]::IsNullOrEmpty($Request.GetInControl($Constants.EDS_CONTROL_SOURCE_OBJECT_DN))) 
        {
            LogEvent -Message "$Function - Source Object DN Empty, existing" -Type "Info"
            return
        }
    
        $EDMSDN = [string]::Format("EDMS://{0}",$Request.GetInControl($Constants.EDS_CONTROL_SOURCE_OBJECT_DN))
        LogEvent -Message "$Function - Source object: $EDMSDN" -Type "Info"
    
        $srcObj = [ADSI]$EDMSDN
           
    
        #-- copy additional attributes
        $SrcObj.GetInfoEx($arrAttributeList, 0)
        
        foreach($strAttrib in $arrAttributeList)
        {
            #-- get source
            try
            {
                $Value = $null
                $Value = $SrcObj.Get($strAttrib)
                LogEvent -Message "$Function - Attribute: $strAttrib - Value: $Value" -Type "Info"
                #-- apply to destination
                if(-Not [string]::IsNullOrEmpty($Value))
                {
                    $DirObj.Put($strAttrib, $Value)
                }
    
            }
            catch
            {}
        }
    
        #-- apply changes
        $DirObj.SetInfo()
    }
    
    function LogEvent
    {    
        param
        (
            [string]$Message,
            [string]$Type
        )
    
        switch($Type.ToLower())
        {
            "Info".ToLower() {$code = $Constants.EDS_EVENTLOG_INFORMATION_TYPE}
            "Warning".ToLower() {$code = $Constants.EDS_EVENTLOG_WARNING_TYPE}
            "Error".ToLower() {$code = $Constants.EDS_EVENTLOG_ERROR_TYPE}
            default {$Code = $null}
        }
        
        if($Code)
        {
            $EventLog.ReportEvent($Code, $Message)
        }
    
    }
    #***** END OF CODE ***************************************************************

    I'd written this earlier, but hadn't got a chance to share, so to back up Johnny's answer Slight smile

  • Thanks so much both of you for the answers. Really appreciate the quick answer and the script example.