Create mailbox and settings checking entire environment- delay because of cmdlet Extension agent (Hosted exchange)

Hello,
we have one problem that is uncommon but its slowing our business as we grow.

We are developing exchange hosted on 2013 and process is quite slow, but it is slow because it is "verifying" all the environmental details like which address lists exists. 

example when i run in verbose mode creation of user looks like this and verifying all the GALs and address lists: 

Keep in mind that it is creation of single user only, so its just too much.

So, the question here is- is this possible to avoid?

I see some article about https://technet.microsoft.com/en-us/library/dd297998%28v=exchg.141%29.aspx disabling cmdlet script agent, so it may be relevant?

Which agent can be related to this checks as we have scenario like this:

PS C:\Windows\system32> Get-CmdletExtensionAgent | Format-Table Name, Enabled, Priority

Name                                                                            Enabled                                    Priority
----                                                                            -------                                    --------
Admin Audit Log Agent                                                              True                                         255
Query Base DN Agent                                                                True                                           1
Rus Agent                                                                          True                                           2
Mailbox Resources Management Agent                                                 True                                           3
Provisioning Policy Agent                                                          True                                           4
OAB Resources Management Agent                                                     True                                           5
Scripting Agent                                                                   False                                           6
Mailbox Creation Time Agent                                                        True                                           0

Maybe someone can give a hint what should be disabled :)?

BTW; here is code for creation user:

##Create User
#==================================================
$ErrorActionPreference = "Stop";
try{
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn
$OrganizationName = "test@test.com" #User defined mail address
$organizationUnit = "OU=$OrganizationName,OU=Tenants,DC=secureemail,DC=priv"; #Pulled out from billing area- OrganizationID, customer ID, whatever it is unique in WHMCS
$name = "Mary"                                             #this should be asked in web interface (firstname)
$lastname = "Doe"                                                #this should be asked in web interface (lastname)
$displayName = "Mary Doe" # this is display name in OWA and in all address books
$logonName = "mary"    # this will be users choosen logon name (before @externaldomain.com)
$ExternalDomain = "test.com"        #this value user will enter as his wanted username and will use it together with his external domain name mary@example.com
$UPN = "$LogonName@$ExternalDomain"   #this should remain to be done automatically and under assumption domain is provisioned!!
$DomainController = "se-server02"   #this value must be specified based on domain controller in AD site where user will be created (se-server02 and se-server02 europe, se-8301 and se-8302 canada, sin-server01 asia)
$nonadmin = "$OrganizationName All Users"; #This is field for entire tenant management and members are used for calendar sharing
$database = "Europe8116"                                #add database here (dropdown in WEB with 3 options Canada, Europe, Asia)
$retentionPolicy = "removeContent8h"
$customattribute1 = "$OrganizationName" #Add for possible manipulation of tenants for future need
$customattribute2 = "ServiceID" #Add data from WHMCS for future reporting
$customattribute3 = "ContactID" #Add data from WHMCS for future reporting
$customattribute4 = "ClientID" # Add data from WHMCS for future reporting
$password =ConvertTo-SecureString 'Password123' -AsPlainText -Force
$mailbox = New-Mailbox -DomainController "$DomainController" -verbose -RetentionPolicy $retentionPolicy -UserPrincipalName $UPN -Name "$name $lastname" -OrganizationalUnit "$organizationUnit" -Password $password -FirstName "$name" -LastName "$lastname" -Displayname "$Displayname" -database $database -ResetPasswordOnNextLogon $false  #This is part where user is created
Add-DistributionGroupMember -Identity "$OrganizationName All Users" -Member $UPN -DomainController $DomainController -Confirm:$false     #at this line user is placed in distribution group and that group is used for additional security
Set-Mailbox -AddressBookPolicy "$OrganizationName ABP" -Identity "$UPN" -DomainController "$DomainController" -verbose #from this point user gets his address book and isolation part.
Set-Mailbox -Identity "$UPN" -DomainController "$DomainController" -verbose -EmailAddressPolicyEnabled:$False #disables force of address policy
Set-Mailbox -identity "$UPN" -PrimarySmtpAddress  $UPN  -DomainController "$DomainController" -verbose ; #assigns default mail address
Set-CASMailbox -identity "$UPN" -OwaMailboxPolicy Default  -DomainController "$DomainController" -verbose #In this policy it is defined that user cant manage his password, as any future change will be managed globally here and automatically applied to all users
set-mailbox -identity $UPN -customattribute1 $customattribute1 -customattribute2 $customattribute2 -customattribute3 $customattribute3 -customattribute4 $customattribute4 -domaincontroller  $domaincontroller
Set-MailboxFolderPermission -identity ${UPN}:\calendar -User default -accessrights none     #removes default free/busy for all users
add-MailboxFolderPermission -Identity ${UPN}:\calendar -user $nonadmin -AccessRights AvailabilityOnly    #only members of classic users can see free/busy
$mailbox | Set-CasMailbox -DomainController "$DomainController" -verbose -ActiveSyncEnabled $true -PopEnabled $true -ImapEnabled $true -OWAEnabled $true -MAPIEnabled $true; #adding script for created user to be returned after creation
Import-Module ActiveDirectory;
repadmin.exe /syncall $DomainController
$temp = Get-Mailbox -DomainController "$DomainController" -verbose -Identity "$UPN"|Select  Alias,Name,FirstName,LastName,DisplayName, RetentionPolicy, UserPrincipalName, OrganizationalUnit, DistinguishedName,SamAccountName, PrimarySmtpAddress, Database,ProhibitSendQuota,ProhibitSendReceiveQuota,IssueWarningQuota,WhenCreated, WhenChanged;
$size = Get-MailboxStatistics -DomainController "$DomainController" -verbose -Identity "$UPN"|Select  TotalItemSize;
$cas = Get-CASMailbox -DomainController "$DomainController" -verbose -Identity "$UPN" | Select ActiveSyncEnabled, PopEnabled, MAPIEnabled, IMAPEnabled, OWAEnabled;
$response = @();
$code = New-Object PSObject Prop @{responseCode="200"};
$response += $code;
$response += $temp;
$response +=$size;
$response += $cas;
$memberof=GET-ADUSER -server $DomainController Identity ($temp | Select-object SamAccountName).SamAccountName Properties MemberOf, Office,OfficePhone, Company, OtherName, Surname,Country,State, City,StreetAddress, POBox, PostalCode, HomePhone, MobilePhone, Fax, Description,LastLogonDate,Created, Modified| Select-Object MemberOf, Office,OfficePhone, Company, OtherName, Surname,Country,State, City,StreetAddress, POBox, PostalCode, HomePhone, MobilePhone, Fax, Description,LastLogonDate,Created, Modified;
$response += $memberof;
$response | ConvertTo-XML -As String;
} catch {
$props = @{responseCode='400';message="Can't create user";
detailMessage="$_"+" CategoryInfo: "+$_.CategoryInfo+", FullyQualifiedErrorId: "+$_.FullyQualifiedErrorId};
$object = New-Object PSObject Prop $props;
$object | ConvertTo-XML -as String;
}
exit-PSSession
$ErrorActionPreference = "Continue";


Keep in mind that all prerequisites like ABP are created with Tenant script, which i can post if needed.

Thanks in advance,

Ivica

September 14th, 2015 7:42am