3 Replies Latest reply on Feb 5, 2019 2:45 AM by 8paul

    Running a powershell script after creation of mailbox


      Hello everyone,


      After creating a mailbox using a template we would like to run a convert.ps1 script which converts the mailbox to shared mailbox.


      The template consists of this code:


         /* (optional) Hide the scripting area. Stronger than IsHiddenFromRequester.


              If a script is defined it will be executed even if the area is hidden. */

              "IsHidden": false,


              // (optional) Hide the scripting area for requesters in web interface. Weaker than IsHidden.

              "IsHiddenFromRequester": false,


              // (optional) Define the checkbox preset. Default is false (if not set).

              "IsScriptEnabledDefault": true,


              // Set a display name.

              "DisplayName": "Convert to Shared Mailbox",


              // Path to the script file. Use UNC format and mention escaping.


         "Path": "\\\\xxxx\\\\xxxxxxxx\\convert.ps1",


              // (optional) Define the parameters that will be passed to the script.

              "CommandLineParameters": "{mail}"      



      It doesn't work this way. The script seems to be running but does not convert the mailbox.


      The script itself looks like this:  


      Start-Sleep -s 60

      Set-Mailbox {mail} -Type shared


      So, we start the job, the user-account/mailbox is created, the ps1 should wait 60 sec and convert the {mail} into a shared mailbox.


      Any ideas how to solve this?



        • Re: Running a powershell script after creation of mailbox

          Hi swg,


          assuming the snippet you posted is just the scriptoptions part of the template and not the complete one that looks ok apart from the path since there would be a double backslash after the server (assuming typo).

          Can you execute the script manually and does it work then? Also if you provide the script path as UNC you will have to loosen up your powershell execution policy further than when using a local path.

          To test if your executionpolicy is hindering the execution set it to "unrestricted" with "Set-Executionpolicy unrestricted". If the script is actually executed and the code just doesn´t work i would suggest debugging the parameter data to make sure it gets passed ok.




            • Re: Running a powershell script after creation of mailbox

              Hi Paul,



              The path was indeed only a typo.


              In the log inside ARM app it says: "[000] powershell.exe -inputformat none -File "\\serverxyz\scriptsfolder\Convert2Shared.ps1" email@xyz.com "      (The email in {mail} is correctly being displayed there)


              Now, I'm not really deep into scripting, but is ARM passing the command in .ps1 to the Exchange Server or do we need the module one the ARM server?

              Set-Executionpolicy unrestricted has been executed (on the ARM server) but nothing seemed to have changed.


              Pretty sure, It's just a simple mistake I'm making there.

                • Re: Running a powershell script after creation of mailbox

                  Hi swg,


                  that looks alright. Re-reading your script, variables in Powershell are referenced with the $ sign and by default parameters will not be named unless you have a parameter definition.

                  For exchange you would also normally create a remote session on the powershell website of the exchange server, here is an example including minimalistic parameter definition:






                  $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "http://<CASServer>/powershell" -Authentication Kerberos

                  Import-PSSession $Session

                  Set-Mailbox $mail -type shared





                  P.S. you should be able to do this without having to install additional modules.