Creating linked mailboxes in resource forest

Hello, everyone. In our project we have met some troubles while creating linked mailboxes. There are two forests A and B. In forest A we have in AD all users. In forest B we have Exchange 2013. Trusts between forests were established.The process would be: IDM create an employee from DB, then create for this employee AD accounts in forest A and forest b, disable the AD account in forest B, create a linked mailbox in forest B and connect it with AD accounts in both forests. We can do it manually through creating a new mailbox and choosing type "linked mailbox" in Manager, but how do this automatically with help e.g. account definitions?