PowerShell Command to Move a Company to Existing Tenent.

postsauravpostsaurav Member Posts: 708
edited 2014-02-07 in NAV Three Tier
Hi all,

Wishing you all a very Happy New Year.

I was working on Mutlitenant and got stuck at one point.

Scenario -
I have 3 companies say A , B & Default.

I want Default in Default Tenant.
I want A & B in a separate tenant say MyTenant.

Here is what i have did till now-
Exported app in a different database.
Mounted App database on the service instance.
created the default Tenant (at this point all 3 companies are in default tenant).

Moved Company A to new Tenant (MyTenant) using below Powershell script -
HowTo-MoveCompanyToTenant -ServerInstance ‘DynamicsNAV71’ -DatabaseServer 'localhost\NAVDEMO' -FromDatabase 'ABC' -CompanyName 'A' -OldTenantName 'default' -NewTenantName 'MYTenant' -ServiceAccount 'NT AUTHORITY\NETWORK SERVICE' -RemoveCompanyWhenMoved

Worked like charm and Company A moved to MyTenant.

But now when i am trying to Move Company B from Default to Mytenant it end up with error.
HowTo-MoveCompanyToTenant -ServerInstance ‘DynamicsNAV71’ -DatabaseServer 'localhost\NAVDEMO' -FromDatabase 'ABC' -CompanyName 'B' -OldTenantName 'default' -NewTenantName 'MYTenant' -ServiceAccount 'NT AUTHORITY\NETWORK SERVICE' -RemoveCompanyWhenMoved

Error -

Mount-NAVTenant : Tenant 'MYTenant' already exists.
At D:\Multitenancy\HowTo-MoveCompanyToTenant.ps1:126 char:5
+ Mount-NAVTenant -Id $NewTenantName -ServerInstance $ServerInstance -Database ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (0:Int32) [Mount-NAVTenant], FaultException`1
+ FullyQualifiedErrorId : MicrosoftDynamicsNavServer$MultiTenent,Microsoft.Dynamics.Nav.Management.Cmdlets.MountNavTenant

I thought it is because MyTenant is Already Mounted, so i dismounted it from Service Instance and ran the command again.

It moved the comany to MyTenant but didnt removed it from default tenant.

ERROR -
Remove-NAVCompany : The Company does not exist. Identification fields and values: Name='B'
At D:\Multitenancy\HowTo-MoveCompanyToTenant.ps1:151 char:11
+ Remove-NAVCompany -ServerInstance $ServerInstance -Tenant $OldTenantNa ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (0:Int32) [Remove-NAVCompany], FaultException`1
+ FullyQualifiedErrorId : MicrosoftDynamicsNavServer$MultiTenent/default,Microsoft.Dynamics.Nav.Management.Cmdlets.RemoveNavCompany

When i checked in SQL the Company B Exists in Both Tenants Default & MyTenant.

So how can i move multiple companies to a tenant and remove it from default tenant.

Thanks in advance

Thanks & Regards,
Saurav Dhyani

Do you Know this About NAV?


Connect - Twitter | Facebook | Google + | YouTube

Follow - Blog | Facebook Page | Google + Page

Answers

Sign In or Register to comment.