I have had a few people asking for this .. So I’m just going to share you my script that I always use to convert a Single Tenancy Demo Environment to a Multi Tenancy Demo Environment, with some (Empty) companies per Tenant and such.. .
And I’m going to make it easy on me .. there are no guarantees that it will work for you out-of-the-box :).
The Script
#Preparing PowerShell Set-ExecutionPolicy RemoteSigned -Force Import-Module 'C:\Program Files\Microsoft Dynamics NAV\71\Service\NavAdminTool.ps1' #Parameters $ServerInstanceName = "DynamicsNAV71" #The current ServiceInstance $DatabaseServer = "localhost" #The Database Server where the database is located $Databasename = "NAV2013R2_BE" #The database that will be migrated to Multi-Tenancy $DemoCompanyName = "CRONUS BELGIË NV" #This company will be renamed to "MainCompany". The data of this company will be available in the Mult-Tenancy environment. $PathToDVD = 'C:\$installs\Dynamics.71.BE.1349272.DVD' #The path to the DVD #The Script $CurrentServerInstance = Get-NAVServerInstance -ServerInstance $ServerInstanceName $MainCompanyName = "MainCompany" $MainTenant = "MainTenant" Write-host "Preparing Companies - Rename and delete default companies" $CurrentServerInstance | Rename-NAVCompany -CompanyName $DemoCompanyName -NewCompanyName $MainCompanyName -Force $DemoCompanies = $CurrentServerInstance | Get-NAVCompany foreach ($DemoCompany in $DemoCompanies) { if (!($DemoCompany.CompanyName -like $MainCompanyName)) { $CurrentServerInstance | Remove-NAVCompany -CompanyName $DemoCompany.CompanyName -Force } } Write-host "Preparing Companies - Create a new company with data" $CurrentServerInstance | Copy-NAVCompany -SourceCompanyName $MainCompanyName -DestinationCompanyName "PRS Company Default" -Force Write-host "Preparing Companies - Creating 10 empty Waldo Companies" for ($i = 1; $i -le 10; $i++) { $CompanyName = 'Waldo Company'+$i $CurrentServerInstance | New-NAVCompany -CompanyName $CompanyName -Force } Write-host "Preparing Companies - Creating 3 empty PRS companies" for ($i = 1; $i -le 3; $i++) { $CompanyName = 'PRS Company'+$i $CurrentServerInstance | New-NAVCompany -CompanyName $CompanyName -Force } Write-host "Split the Application Database and Customer Data" Export-NAVApplication -DatabaseServer $DatabaseServer -DatabaseName $Databasename -DestinationDatabaseName "ApplicationDB" -Force Remove-NAVApplication -DatabaseServer $DatabaseServer -DatabaseName $Databasename -Force Write-host "Prepare NST for MultiTenancy" $CurrentServerInstance | Set-NAVServerInstance -stop $CurrentServerInstance | Set-NAVServerConfiguration -KeyName MultiTenant -KeyValue "true" $CurrentServerInstance | Set-NAVServerConfiguration -KeyName DatabaseName -KeyValue "" $CurrentServerInstance | Set-NAVServerInstance -start Write-host "Mount app" $CurrentServerInstance | Mount-NAVApplication -DatabaseServer $DatabaseServer -DatabaseName "ApplicationDB" Write-host "Create Tenants and move companies" Mount-NAVTenant -ServerInstance DynamicsNAV71 -Id $MainTenant -DatabaseName $Databasename -AllowAppDatabaseWrite -OverwriteTenantIdInDatabase import-module "$PathToDVD\WindowsPowerShellScripts\Multitenancy\NAVMultitenancySamples" -verbose Write-host "Move PRS Companies" $MoveToTenant = 'PRS Company' Get-NAVServerINstance | Get-NAVCompany -Tenant $MainTenant | Where-Object { $_."CompanyName" -like $MoveToTenant + '*' } | HowTo-MoveCompanyToTenant -ServerInstance $CurrentServerInstance.ServerInstance -FromDatabase 'NAV2013R2_BE' -OldTenantName $MainTenant -NewTenantName $MoveToTenant.Replace(" ","") -RemoveCompanyWhenMoved Write-host "Move Waldo Companies" $MoveToTenant = 'Waldo Company' Get-NAVServerINstance | Get-NAVCompany -Tenant $MainTenant | Where-Object { $_."CompanyName" -like $MoveToTenant + '*' } | HowTo-MoveCompanyToTenant -ServerInstance $CurrentServerInstance.ServerInstance -FromDatabase 'NAV2013R2_BE' -OldTenantName $MainTenant -NewTenantName $MoveToTenant.Replace(" ","") -RemoveCompanyWhenMoved
Some words of explanation
As you see, I’m usually working with a Belgian database. The “parameters” section should help you to easily change the script to your own needs.
Furtheron, I’m just going to keep 1 active company (Belgian version has 2), copy it to a PRS company, create 13 more companies and going to create multiple tenants with each tenant some companies.. . Just try it out, and see what happens :).
The Result
It creates for you a Multi-Tenancy environment with three tenants:
-
“MainTenant” will have 1 company, being “MainCompany”. Check With:
Get-NAVServerInstance | Get-NAVCompany -tenant “MainTenant”
-
“prscompany” will have 4 companies. One with data (PRS Company). Check With:
Get-NAVServerInstance | Get-NAVCompany -tenant “prscompany”
-
“waldocompany” will have 10 empty companies. Check with:
Get-NAVServerInstance | Get-NAVCompany -tenant “waldocompany”
Good luck!
9 comments
1 pings
Skip to comment form
Thank you Waldo.
It seems that the two of us are getting hooked on PowerShell…
Author
We sure are 🙂
Hello waldo, first of all thanks for your help and collaboration; you think do a demo video of this case?
Author
There actually is: https://www.youtube.com/watch?v=thQFJGTYA0E
🙂
Hello waldo, I’ve a problem:
1. I’ve a default Serverinstance DynamicsNAV71 with single tenent.
2. from SQLServer 2012 i’ve done a backUp of Demo DB with 4 company in it and then
3. i’ve create new DB MyDB from the backup.
4. From NAV2013 R2 development env, I’m able to see my MYDB
now, I need to remove, via REMOVE-NAVCompany cmdlet, all the companies from MyDB but i’m not able to force MyDB name in remove-NAVCompany cmdlet.
have you any idea about?
Thanks
Author
You have to set up a service tier, before you can use any *-NAVCompany commandlet.. . So set up a service tier first, and off you go.
Hi Waldo, I’ve been following some of your posts and videos. My question may seem to be silly to you – I want to set up two demo DB – one is cronus international and other cronus australia. What is the procedure? Please treat me complete novice while replying.. :), thanks in advance.
Hi Waldo, just adding more info before your answer. I’ve installed cronus international using Nav 2013 R2, now trying to install cronus AU. I’ve developer env., powershell, admin tool, RTC & sql server mgt. studio installed on my system.
Author
Sorry, man .. really don’t know what you mean.
I’d like to encourage you to go to http://www.mibuso.com and use the forum. Lots of people will be able to help you.
[…] Continue reading » […]