Exchange 2013: Deactivate mailbox features (Scripting Agent)

Exchange Server 2013 (and also Exchange 2010) provides a function to influence the behavior of standard CMDlets.

In this small example, the scripting agent is used to deactivate OWA, OWA for devices and ActiveSync for all newly created mailboxes. In the default setting, these mailbox functions are activated, which may not always be desired. However, a few steps are necessary to activate the Scripting Agent and thus adjust the behavior of standard CMDlets:

The Scripting Agent is configured using an XML file, which must be present on every Exchange server. An example file is already available in the Exchange installation folder:

C:\Program Files\Microsoft\Exchange Server\V15\Bin\CmdletExtensionAgents

image

The file "ScriptingAgentConfig.xml.sample" can be used as a template by simply removing the ".sample". This step must be carried out on every Exchange Server. Each Exchange server therefore receives the same "ScriptingAgentConfig.xml" file:

image

For this example, the "ScriptingAgentConfig.xml" file has the following content:

Scripting Agent

You can also download the file here:

As can be seen in the example file, the XML file contains some PowerShell code, which in this case is executed when the CMDLet "new-mailbox" or "enable-mailbox" has been successfully completed. The part within the IF statement then retrieves the alias of the mailbox that was edited and deactivates the corresponding mailbox features.

As soon as the XML file has been placed on the Exchange servers, the scripting agent must be activated:

Enable-CmdletExtensionAgent "Scripting Agent"

image

Mailboxes that are created from now on no longer have ActiveSync, OWA and OWA for devices activated

image

Other scenarios can also be implemented by making a few adjustments to the XML file. Switching on UC or audit, setting mailbox authorizations, calendar settings, or even an OWA signature, many things are conceivable.

The sample file on the Exchange servers is also well commented so that you can quickly find the relevant instructions.

9 thoughts on “Exchange 2013: Postfach Features deaktivieren (Scripting Agent)”

  1. Hi ich bekomme folgende Warnung beim erstellen neuer User nachdem ich das ausprobieren wollte:

    Der Cmdlet-Erweiterungs-Agent mit dem Index 5 hat eine Ausnahme in ‚OnComplete()‘ ausgelöst: Microsoft.Exchange.Provisioning.ProvisioningException: ScriptingAgent: Beim Aufrufen des Scriptlets für die OnComplete-API wurde eine Ausnahme ausgelöst: Der Vorgang konnte nicht ausgeführt werden, weil das Objekt ‚Testuser‘ nicht auf ‚AD-ControllerX‘ gefunden wurde.. —> Microsoft.Exchange.Configuration.Tasks.ManagementObjectNotFoundException: Der Vorgang konnte nicht ausgeführt werden, weil das Objekt ‚Testuser‘ nicht auf ‚AD-ControllerX‘ gefunden wurde. bei Microsoft.Exchange.Configuration.Tasks.Task.ThrowError(Exception exception, ErrorCategory errorCategory, Object target, String helpUrl) bei Microsoft.Exchange.Configuration.Tasks.GetObjectWithIdentityTaskBase`2.InternalProcessRecord() bei Microsoft.Exchange.Configuration.Tasks.GetRecipientObjectTask`2.InternalProcessRecord() bei Microsoft.Exchange.Management.RecipientTasks.GetRecipientWithAddressListBase`2.InternalProcessRecord() bei Microsoft.Exchange.Configuration.Tasks.Task.b__91_1() bei Microsoft.Exchange.Configuration.Tasks.Task.InvokeRetryableFunc(String funcName, Action func, Boolean terminatePipelineIfFailed) — Ende der internen Ausnahmestapelüberwachung — bei Microsoft.Exchange.ProvisioningAgent.ScriptingAgentHandler.OnComplete(Boolean succeeded, Exception e) bei Microsoft.Exchange.Provisioning.ProvisioningLayer.OnCompleteImpl(Task task, Boolean succeeded, Exception exception)

    Kann das daran liegen das wir unsere Userobjekte in der AD Struktur wegsortieren nach bestimmten OU? Und somit die AD User Objekte nicht im Default Container „Users“ liegen.

    Reply
  2. Hallo Frank,
    der Blogpost ist zwar schon etwas in die Jahre gekommen, ich hätte da aber dennoch eine ggf. wichtige Anmerkung. In dem config File holst Du Dir die zu konfigurierende Mailbox mit dem Benutzerdefinierten Parameter „alias“. Sollte dieser, warum auch immer nicht angegeben worden sein, dann wird automatisch set-casmailbox auf (fast)alle CASMailboxen angewendet. Ich würde noch einen Sicherheitsschalter einbauen, um sicher zu gehen, dass nicht ungewollt Set -Befehle auf alle Mailboxen angewendet werden. z.B. If ($alias){}
    PS: Einziger limitierender Faktor ist das von Get-Mailbox vorgegebene ResultSize Limit
    Viele Grüße, Matthias.

    Reply
  3. Hi Frank,
    danke für den Artikel. Hab dein Script heruntergeladen und entsprechend abgelegt (EXCH 2016)-Leider bekommen ich die Fehlermeldung
    „Fehler bei der Initialisierung der Bereitstellungsebene: ‚“Fehler bei der Initialisierung des Skript-Agents: Unerwartete XML-Deklaration. Die XML-Deklaration muss der erste Knoten im Dokument sein. Davor sind keine Leerzeichen zulässig. Zeile 2, Position 3.“‚

    Hast du eine Idee?
    Danke und Gruß

    Reply
  4. Hallo Frank,

    vielen Dank, jedoch (wenn ich 1:1 kopiere) deaktiviert es bei mir bei ALLEN den ActiveSync-Dienst.
    (Exch2016)

    Reply
  5. Hallo Frank!

    Danke für die tolle Anleitung…
    Aber ich bekomme ständig diese Fehlermeldung:

    Der Cmdlet-Erweiterungs-Agent mit dem Index 5 hat eine Ausnahme in ‚OnComplete()‘ ausgelöst: Microsoft.Exchange.Provisioning.ProvisioningException: ScriptingAgent: Beim Aufrufen des Scriptlets für die OnComplete-API wurde eine Ausnahme ausgelöst: Cannot convert ‚System.Object[]‘ to the type ‚Microsoft.Exchange.Configuration.Tasks.MailboxIdParameter‘ required by parameter ‚Identity‘. Specified method is not supported.. —> System.Management.Automation.ParameterBindingException: Cannot convert ‚System.Object[]‘ to the type ‚Microsoft.Exchange.Configuration.Tasks.MailboxIdParameter‘ required by parameter ‚Identity‘. Specified method is not supported. —> System.NotSupportedException: Specified method is not supported. at System.Management.Automation.ParameterBinderBase.CoerceTypeAsNeeded(CommandParameterInternal argument, String parameterName, Type toType, ParameterCollectionTypeInformation collectionTypeInfo, Object currentValue) — End of inner exception stack trace — at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object input, Hashtable errorResults, Boolean enumerate) at System.Management.Automation.PipelineOps.InvokePipeline(Object input, Boolean ignoreInput, CommandParameterInternal[][] pipeElements, CommandBaseAst[] pipeElementAsts, CommandRedirection[][] commandRedirections, FunctionContext funcContext) at System.Management.Automation.Interpreter.ActionCallInstruction`6.Run(InterpretedFrame frame) at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) — End of inner exception stack trace — at Microsoft.Exchange.ProvisioningAgent.ScriptingAgentHandler.OnComplete(Boolean succeeded, Exception e) at Microsoft.Exchange.Provisioning.ProvisioningLayer.OnCompleteImpl(Task task, Boolean succeeded, Exception exception)

    Mit Bitte um Hilfe!
    Danke!

    Reply

Leave a Comment