none
cmdlet scripting agent for multi-domain environment RRS feed

  • Question

  • I tried to use cmdlet scripting agent to update some mailbox settings after New-Mailbox or Enable-Mailbox in a single-site/multi-domains environment.  I am getting "Microsoft.Exchange.Provisioning.ProvisioningException: ScriptingAgent: Exception thrown while invoking scriptlet for OnComplete API: Cannot open mailbox /o=CITY/ou=Exchange Administrative Group (FYDIBOHF23SPDLT)/cn=Configuration/cn=Servers/cn=COWSVPEMM3/cn=Microsoft System Attendant.. ---> Microsoft.Exchange.Data.Storage.ObjectNotFoundException: Cannot open mailbox" and I think this is due to replication delay.  I tried to use [string]($readOnlyIConfigurable.originatingserver) to obtain the DC used in the session, so I can force the script to use the same DC but ($readOnlyIConfigurable.originatingserver)  return a blank value.  Does that make sense?  Is there any other way to retrieve the DC info? 

    thanks



    Tuesday, September 2, 2014 4:02 AM

Answers

  • Попробуй добавить выделенный вызов, перед OnComplete. Переменная $readOnlyIConfigurable.originatingserver далее не  будет пустая.

    <Feature Name="MailboxProvisioning" Cmdlets="new-mailbox,Enable-Mailbox">
    <ApiCall Name="Validate">
    </ApiCall>
    <ApiCall Name="OnComplete">


    • Marked as answer by AndyHWC Monday, September 8, 2014 1:22 PM
    Monday, September 8, 2014 11:16 AM

All replies

  • The error is saying some cmdlet is getting a null value for parameter -identity where it's required. It's unclear from the post which cmdlet, or the rest of the script. Can you post these details?

    Sam Boutros, Senior Consultant, Software Logic, KOP, PA http://superwidgets.wordpress.com (Please take a moment to Vote as Helpful and/or Mark as Answer, where applicable)

    Tuesday, September 2, 2014 10:07 AM
  • The error is saying some cmdlet is getting a null value for parameter -identity where it's required. It's unclear from the post which cmdlet, or the rest of the script. Can you post these details?

    Sam Boutros, Senior Consultant, Software Logic, KOP, PA http://superwidgets.wordpress.com (Please take a moment to Vote as Helpful and/or Mark as Answer, where applicable)

    Below is the code, even a start-sleep 20 didn't help but start-sleep 300 seems to work.  according to c:\temp\cmdlet.log, $DC is blank.  $mbx is blank most of the time unless there is 300 sec delay. 

     <Feature Name="MailboxProvisioning" Cmdlets="new-mailbox,Enable-Mailbox">
         <ApiCall Name="OnComplete">

      if($succeeded)
      {
      #start-sleep 300
      $DC = [string]($readOnlyIConfigurable.originatingserver)
      $DC >> c:\temp\cmdlet.log

        $mbx = ($provisioningHandler.UserSpecifiedParameters["Name"]).ToString()
      
      if ($mbx -eq $null) {
       $mbx = ($provisioningHandler.UserSpecifiedParameters["Identity"]).ToString()
         }

      $mbx >> c:\temp\cmdlet.log

      Set-MailboxRegionalConfiguration $mbx -Language "en-us" -TimeZone "Central Standard Time" -DomainController $DC.ad.cityofwpg.org
           Set-CASMailbox $mbx -mapiblockoutlookrpchttp $true -ImapEnabled $False -POPEnabled $False -DomainController $DC.ad.cityofwpg.org


      }
         </ApiCall>

     </Feature>


    Tuesday, September 2, 2014 12:47 PM
  • try 

    Set-AdServerSettings -ViewEntireForest $true

    Tuesday, September 2, 2014 4:20 PM
  • try 

    Set-AdServerSettings -ViewEntireForest $true

    thanks, $DC is still blank.  And the script returned below warning:

    Summary: 1 item(s). 1 succeeded, 0 failed.
    Elapsed time: 00:00:02


    zztest3
    Completed

    Warning:
    The cmdlet extension agent with the index 5 has thrown an exception in OnComplete(). The exception is: Microsoft.Exchange.Provisioning.ProvisioningException: ScriptingAgent: Exception thrown while invoking scriptlet for OnComplete API: Cannot open mailbox /o=CITY/ou=Exchange Administrative Group (FYDIBOHF23SPDLT)/cn=Configuration/cn=Servers/cn=COWSVPEMM3/cn=Microsoft System Attendant.. ---> Microsoft.Exchange.Data.Storage.ObjectNotFoundException: Cannot open mailbox /o=CITY/ou=Exchange Administrative Group (FYDIBOHF23SPDLT)/cn=Configuration/cn=Servers/cn=COWSVPEMM3/cn=Microsoft System Attendant. ---> Microsoft.Mapi.MapiExceptionNotFound: MapiExceptionNotFound: Unable to open message store. (hr=0x8004010f, ec=-2147221233)
    Diagnostic context:
        Lid: 55847   EMSMDBPOOL.EcPoolSessionDoRpc called [length=176]
        Lid: 43559   EMSMDBPOOL.EcPoolSessionDoRpc returned [ec=0x0][length=344][latency=15]
        Lid: 23226   --- ROP Parse Start ---
        Lid: 27962   ROP: ropLogon [254]
        Lid: 17082   ROP Error: 0x8004010F
        Lid: 26937 
        Lid: 21921   StoreEc: 0x8004010F
        Lid: 27962   ROP: ropExtendedError [250]
        Lid: 1494    ---- Remote Context Beg ----
        Lid: 26426   ROP: ropLogon [254]
        Lid: 22086 
        Lid: 25876 
        Lid: 7588    StoreEc: 0x8004010F
        Lid: 25840 
        Lid: 6564    StoreEc: 0x8004010F
        Lid: 17597   Error: 0x0
        Lid: 25805   Error: 0x0
        Lid: 8936    StoreEc: 0x8004010F
        Lid: 22957   Error: 0x0
        Lid: 19693   Error: 0x0
        Lid: 17917   Error: 0x0
        Lid: 16893   Error: 0x0
        Lid: 28877   Error: 0x0
        Lid: 14312   StoreEc: 0x8004010F
        Lid: 25516   StoreEc: 0x8004010F
        Lid: 64055 
        Lid: 2199    StoreEc: 0x8004010F
        Lid: 56415 
        Lid: 25805   Error: 0x0
        Lid: 8936    StoreEc: 0x8004010F
        Lid: 8936    StoreEc: 0x8004010F
        Lid: 48223   StoreEc: 0x8004010F
        Lid: 17097   StoreEc: 0x8004010F
        Lid: 8620    StoreEc: 0x8004010F
        Lid: 1750    ---- Remote Context End ----
        Lid: 26849 
        Lid: 21817   ROP Failure: 0x8004010F
        Lid: 26297 
        Lid: 16585   StoreEc: 0x8004010F
        Lid: 32441 
        Lid: 1706    StoreEc: 0x8004010F
        Lid: 24761 
        Lid: 20665   StoreEc: 0x8004010F
        Lid: 25785 
        Lid: 29881   StoreEc: 0x8004010F
       at Microsoft.Mapi.MapiExceptionHelper.ThrowIfError(String message, Int32 hresult, SafeExInterfaceHandle iUnknown, Exception innerException)
       at Microsoft.Mapi.ExRpcConnection.OpenMsgStore(OpenStoreFlag storeFlags, String mailboxDn, Guid mailboxGuid, Guid mdbGuid, MapiStore msgStorePrivate, String& correctServerDn, ClientIdentityInfo clientIdentityAs, String userDnAs, String applicationId, CultureInfo cultureInfo)
       at Microsoft.Mapi.MapiStore.OpenMapiStore(String serverDn, String userDn, String mailboxDn, Guid guidMailbox, Guid guidMdb, String userName, String domainName, String password, String httpProxyServerName, ConnectFlag connectFlags, OpenStoreFlag storeFlags, CultureInfo cultureInfo, Boolean wantRedirect, String& correctServerDN, ClientIdentityInfo clientIdentity, String applicationId, Client xropClient, Boolean wantWebServices, Byte[] clientSessionInfo, TimeSpan connectionTimeout)
       at Microsoft.Mapi.MapiStore.OpenMailbox(String serverDn, String userDn, Guid guidMailbox, Guid guidMdb, String userName, String domainName, String password, ConnectFlag connectFlags, OpenStoreFlag storeFlags, CultureInfo cultureInfo, WindowsIdentity windowsIdentity, String applicationId)
       at Microsoft.Exchange.Data.Storage.MailboxSession.ForceOpen(MapiStore linkedStore)
       --- End of inner exception stack trace ---
       at Microsoft.Exchange.Data.Storage.MailboxSession.ForceOpen(MapiStore linkedStore)
       at Microsoft.Exchange.Data.Storage.MailboxSession.Initialize(MapiStore linkedStore, LogonType logonType, ExchangePrincipal owner, DelegateLogonUser delegateUser, Object identity, OpenMailboxSessionFlags flags, GenericIdentity auxiliaryIdentity)
       at Microsoft.Exchange.Data.Storage.MailboxSession.<>c__DisplayClass12.<CreateMailboxSession>b__10(MailboxSession mailboxSession)
       at Microsoft.Exchange.Data.Storage.MailboxSession.InternalCreateMailboxSession(LogonType logonType, ExchangePrincipal owner, CultureInfo cultureInfo, String clientInfoString, IAccountingObject budget, Action`1 initializeMailboxSession, InitializeMailboxSessionFailure initializeMailboxSessionFailure)
       at Microsoft.Exchange.Data.Storage.MailboxSession.CreateMailboxSession(LogonType logonType, ExchangePrincipal owner, DelegateLogonUser delegateUser, Object identity, OpenMailboxSessionFlags flags, CultureInfo cultureInfo, String clientInfoString, PropertyDefinition[] mailboxProperties, IList`1 foldersToInit, GenericIdentity auxiliaryIdentity, IAccountingObject budget)
       at Microsoft.Exchange.Data.Storage.MailboxSession.ConfigurableOpen(ExchangePrincipal mailbox, MailboxAccessInfo accessInfo, CultureInfo cultureInfo, String clientInfoString, LogonType logonType, PropertyDefinition[] mailboxProperties, InitializationFlags initFlags, IList`1 foldersToInit, IAccountingObject budget)
       at Microsoft.Exchange.Data.Storage.MailboxSession.OpenAsAdmin(ExchangePrincipal mailboxOwner, MailboxAccessInfo accessInfo, LogonType logonType, CultureInfo cultureInfo, String clientInfoString, Boolean useLocalRpc, Boolean ignoreHomeMdb, Boolean recoveryDatabase)
       at Microsoft.Exchange.Data.Storage.MailboxSession.OpenAsAdmin(ExchangePrincipal mailboxOwner, CultureInfo cultureInfo, String clientInfoString, Boolean useLocalRpc, Boolean ignoreHomeMdb, GenericIdentity auxiliaryIdentity)
       at Microsoft.Exchange.Data.Storage.MailboxSession.OpenAsAdmin(ExchangePrincipal mailboxOwner, CultureInfo cultureInfo, String clientInfoString)
       at Microsoft.Exchange.Management.StoreTasks.StoreTasksHelper.OpenMailboxSession(ExchangePrincipal principal, String taskName)
       at Microsoft.Exchange.Management.StoreTasks.SetMailboxRegionalConfiguration.CreateMailboxDataProvider(ADUser adUser)
       at Microsoft.Exchange.Management.StoreTasks.SetMailboxConfigurationTaskBase`1.CreateSession()
       at Microsoft.Exchange.Configuration.Tasks.DataAccessTask`1.InternalStateReset()
       at Microsoft.Exchange.Configuration.Tasks.SetObjectTaskBase`2.InternalStateReset()
       at Microsoft.Exchange.Configuration.Tasks.SetTenantADTaskBase`3.InternalStateReset()
       at Microsoft.Exchange.Management.StoreTasks.SetMailboxConfigurationTaskBase`1.InternalStateReset()
       at Microsoft.Exchange.Configuration.Tasks.Task.ProcessRecord()
       --- End of inner exception stack trace ---
       at Microsoft.Exchange.ProvisioningAgent.ScriptingAgentHandler.OnComplete(Boolean succeeded, Exception e)
       at Microsoft.Exchange.Provisioning.ProvisioningLayer.OnComplete(Task task, Boolean succeeded, Exception exception)

    Exchange Management Shell command completed:
    Enable-Mailbox -Identity 'ad.domain/someOU/zztest3' -Alias 'zztest3'

    Elapsed Time: 00:00:02

    Tuesday, September 2, 2014 4:33 PM
  • I updated the original post to reflect the correct error message I am getting. The "Null" value is a different issue that I already fixed.    So I guess I need to find a way to retrieve the DC used by the session.  $readOnlyIConfigurable.originatingserver) supposes to give me this info but unfortunately I got blank value in both our production and test Exchange 2010 environment.  is there any other way to get the DC info? 

    thanks

    Wednesday, September 3, 2014 1:15 PM
  • For multiple domain you either need to define those domains or use get-DomainController

    if($succeeded)

    {
         start-sleep -s 300
         $mbx = $provisioningHandler.UserSpecifiedParameters["Name"]
         $DCs = get-domaincontroller

     if ($mbx -eq $null) {
       $mbx = ($provisioningHandler.UserSpecifiedParameters["Identity"])     

                                 }

    .......

    later you may have to use a loop to make sure you can leverage the loop. Sorry my account do not allow me to add http links else would have send you example.

    Thursday, September 4, 2014 1:11 AM
  • For multiple domain you either need to define those domains or use get-DomainController

    if($succeeded)

    {
         start-sleep -s 300
         $mbx = $provisioningHandler.UserSpecifiedParameters["Name"]
         $DCs = get-domaincontroller

     if ($mbx -eq $null) {
       $mbx = ($provisioningHandler.UserSpecifiedParameters["Identity"])     

                                 }

    .......

    later you may have to use a loop to make sure you can leverage the loop. Sorry my account do not allow me to add http links else would have send you example.

    thanks for the reply but sorry, I don't get it.  Get-domaincontroller will return list of available DC but what I need is the DC used by the enable-mailbox or new-mailbox to create the mailbox, so my code will not get "mailbox not found" error.   

    Or are you suggesting trying all the DCs using a for loop? 

    Thursday, September 4, 2014 4:28 AM
  • Попробуй добавить выделенный вызов, перед OnComplete. Переменная $readOnlyIConfigurable.originatingserver далее не  будет пустая.

    <Feature Name="MailboxProvisioning" Cmdlets="new-mailbox,Enable-Mailbox">
    <ApiCall Name="Validate">
    </ApiCall>
    <ApiCall Name="OnComplete">


    • Marked as answer by AndyHWC Monday, September 8, 2014 1:22 PM
    Monday, September 8, 2014 11:16 AM
  • Попробуй добавить выделенный вызов, перед OnComplete. Переменная $readOnlyIConfigurable.originatingserver далее не  будет пустая.

    <Feature Name="MailboxProvisioning" Cmdlets="new-mailbox,Enable-Mailbox">
    <ApiCall Name="Validate">
    </ApiCall>
    <ApiCall Name="OnComplete">


    This is it!  Спасибо вам!

    Kind of off-topic, now the set-mailbox -language gave me below error from scripting agent, the same command works fine if I type in the command with EMS. 

    Microsoft.Exchange.Provisioning.ProvisioningException: ScriptingAgent: Exception thrown while invoking scriptlet for OnComplete API: Property Languages can't be set on this object because it requires the object to have version 0.1 (8.0.535.0) or later. The object's current version is 0.0 (6.5.6500.0).. ---> System.InvalidOperationException: Property Languages can't be set on this object because it requires the object to have version 0.1 (8.0.535.0) or later. The object's current version is 0.0 (6.5.6500.0).

    Monday, September 8, 2014 1:25 PM
  • I were suggesting loop if you want to deal with all DCs or define $DC and give it value front hand.
    Wednesday, September 17, 2014 3:31 AM
  • I have the same problem.

    Here is conf file:

     <Feature Name="NewMailbox" Cmdlets="new-Mailbox">
    <ApiCall Name="Validate">
    </ApiCall>
    <ApiCall Name="OnComplete">
        if($succeeded)    {
    $DC = [string]($readOnlyIConfigurable.originatingserver)
                    $newmailbox = $provisioningHandler.UserSpecifiedParameters["Name"]
                    Set-mailbox -Identity $Newmailbox -MaxSendSize 15Mb -MaxReceiveSize 20Mb -DomainController $DC.mydomain.local
        }
       </ApiCall>
      </Feature>
     </Configuration>

    Could you tell me where is wrong Please?

    But I've decided problems with

    <ApiCall Name="OnComplete">
        if($succeeded)    {
    $DC = (Get-ADServerSettings).DefaultConfigurationDomainController
                    $newmailbox = $provisioningHandler.UserSpecifiedParameters["Name"]
                    Set-mailbox -Identity $Newmailbox -MaxSendSize 15Mb -MaxReceiveSize 20Mb -DomainController $DC }

       </ApiCall>

    Thursday, February 11, 2016 2:11 PM