Unable to modify attribute in onPostCreate

Hello,

I am trying to modify the attribute ""edsvaSendAsTrustees" in $DirObj in the function onPostCreate. My PowerShell function that is called in the onPostCreate looks like this:

#========================================================================================================================================
# Add-MailboxPermissionSendAs
#========================================================================================================================================

function Add-MailboxPermissionSendAs {

param (
[parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string]$DistinguishedName
);

try {
$DirObj.PutEx($Constants.ADS_PROPERTY_APPEND, "edsvaSendAsTrustees", $DistinguishedName)
$DirObj.SetInfo()
return 0;
}
catch {
throw ("[Library : Default : Add-MailboxPermissionSendAs]`n" + ($Error[0]).Exception);
}
}

When I run it, I get the following error (infinite loop at $DirObj.SetInfo()):

Post-processing operation on object caused a policy violation.
Policy: Runs the script 'Policy : User'
Object: cn=mailboxtest,OU=XX,OU=XX,OU=XX,OU=XX,DC=XX,DC=XX
Details: The 'Script Execution' policy encountered an error when running the script 'Policy : User'.
At line: 492 char:5. [Policy : User : onPostCreate]
System.Management.Automation.RuntimeException: [Library : Default : New-ResourceMailboxGroups]
System.Management.Automation.RuntimeException: [Library : Default : Add-MailboxPermissionSendAs]
System.Management.Automation.MethodInvocationException: Exception calling "SetInfo" with "0" argument(s): "The 'Script Execution' policy encountered an error when running the script 'Policy : User'.

At line: -4250 char:1. The script failed due to call depth overflow.

" ---> System.Runtime.InteropServices.COMException: The 'Script Execution' policy encountered an error when running the script 'Policy : User'.

At line: -4250 char:1. The script failed due to call depth overflow.


--- End of inner exception stack trace ---
at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception)
at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)

According to the documentation in the SDK, calling SetInfo() in onPreModify and onPostModify can lead to an infinite loop, but onPostCreate is not listed here.

Is there a workaround for this as well, as mentioned in the SDK or is it simply not possible to set attributes in the DirObj in onPostCreate?

I have already used debug messages to output everything and the error surely comes when calling .SetInfo()

Thanks and best regards
Stefan

  • I generally don't use $DirObj for setting properties.

    2 other options:

    # Put this in your OnPostCreate

    $InProcObj = [ADSI]"EDMS://$Request.DN"
    $InProcObj.putex(3,"edsvaSendAsTrustees",$DistinguishedName)
    $InProcObj.setinfo()

    OR

    Use a change workflow with a Property Setting Activity - not sure where you are getting $DistinguishedName value from but you can pass it to the set property activity from a script if need be.

  • Thank you! :) The first option worked perfectly for me.

  • Back from vacation and now the error comes again :/

    System.Management.Automation.MethodInvocationException: Exception calling "setinfo" with "0" argument(s): "The 'Script Execution' policy encountered an error when running the script 'Policy : User'.

    At line: -4255 char:1. The script failed due to call depth overflow.

    Is there a way to bypass setinfo without the change workflow?