How to: Export and Import Companies and Other Data using Windows PowerShell Cmdlets

You can export data such as a company or an application from a Microsoft Dynamics NAV database from the Microsoft Dynamics NAV 2016 Administration Shell. You can also use Windows PowerShell cmdlets to import data into a Microsoft Dynamics NAV database.

The cmdlets take different parameter sets depending on how you connect to the database that you want to export data from or import data into. You can access the database through the Microsoft Dynamics NAV Server instance, or you can access the database directly. The procedures in this topic illustrate both approaches. For more information, see Exporting and Importing Companies and Other Data.

To export data using Windows PowerShell cmdlets

  1. Open the Microsoft Dynamics NAV 2016 Administration Shell.

    Important

    You must run the program as administrator. Also, you must ensure that scripting is enabled on the computer. You must also have write access to the location that you specify in the –FilePath parameter.

  2. For an overview of the cmdlet, type the following command:

    get-help Export-NAVData
    
  3. To export a single company from a tenant database that is mounted against a Microsoft Dynamics NAV Server instance, type the following command:

    Export-NAVData -ServerInstance <service name> -Tenant <tenant ID> -CompanyName "<Company name>" -FilePath <location>
    

    For example, to run the cmdlet against the CRONUS International Ltd. demonstration database, type the following command:

    Export-NAVData -ServerInstance DynamicsNAV90 -Tenant Tenant1 -CompanyName "CRONUS International Ltd." -FilePath c:\Data\mytenantcompany.navdata
    

    In the example, the Microsoft Dynamics NAV Server instance is DynamicsNAV90, the tenant database is Tenant1, and the company name is CRONUS International Ltd.. The example is based on a multitenant deployment where you want to export a specific company from the specified tenant database. In a single-tenant deployment, you do not specify the tenant, and the example will export the company from the database that the specified Microsoft Dynamics NAV Server instance is configured for.

    For an example of how to export data directly from a database that is not mounted against a Microsoft Dynamics NAV Server instance, see the next step.

  4. To export global data, application data, and application objects directly from a database, type the following command:

    Export-NAVData -DatabaseServer <service name> -Database <database name> -IncludeGlobalData -IncludeApplicationData –IncludeApplication -FilePath <location>
    

    For example, to run the cmdlet against the CRONUS International Ltd. demonstration database, type the following command:

    Export-NAVData - DatabaseServer localhost -DatabaseName 'Demo Database NAV (9-0)' –AllCompanies -IncludeGlobalData -IncludeApplicationData -IncludeApplication -FilePath c:\Data\myappanddata.navdata
    

    In the example, the database server is the local computer, the database is the demonstration database, and the export includes global data, application data, and the application objects, and all companies in the database. The example is based on a single-tenant deployment where you have chosen to specify the –DatabaseServer and –DatabaseName parameters. Alternatively, you can specify the –ServerInstance parameter as illustrated in the previous step. In a multitenant deployment, you must also specify the tenant database.

For another example of how to export companies and other data, see the Example section.

You have exported a Microsoft Dynamics NAV company into a file. Now, you can import the company into another Microsoft Dynamics NAV database.

To import data using Windows PowerShell cmdlets

  1. Open the Microsoft Dynamics NAV 2016 Administration Shell.

    Important

    You must run the program as administrator. Also, you must ensure that scripting is enabled on the computer.

  2. To see what a .navdata file contains, type the following command:

    Get-NAVDataFile -FilePath <location>
    

    For example, to run the cmdlet against one of the files that were exported in the previous procedure, type the following command:

    Get-NAVDataFile -FilePath c:\Data\myappanddata.navdata
    

    In the example, the command returns the following information:

    ExportVersion               : 1
    DatabaseVersion                  : 70730
    Description                      : All companies and all other data from a database.
    IncludeApplication               : True
    IncludeApplicationData           : True
    TenantId                         :  
    IncludeGlobalData                : True
    CompanyName                      : {CRONUS International Ltd.} 
    ExportDateTime                   : 28-08-2014 11:17:16
    
  3. To import a single company into a tenant database that is mounted against a Microsoft Dynamics NAV Server instance, type the following command:

    Import-NAVData -ServerInstance <server name> -Tenant <tenant ID> -CompanyName "<Company name>" -FilePath <location>
    

    For example, to run the cmdlet based on the data that you exported in the previous procedure, type the following command:

    Export-NAVData -ServerInstance DynamicsNAV90 -Tenant Tenant2 -CompanyName "CRONUS International Ltd." -FilePath c:\Data\mytenantcompany.navdata
    

    In the example, the Microsoft Dynamics NAV Server instance is DynamicsNAV90, the tenant database is Tenant2, and the company name is CRONUS International Ltd.. The example is based on a multitenant deployment where you want to move a company from one tenant database to another tenant database. In a single-tenant deployment, you do not specify the tenant, and the example will import the company into the database that the specified Microsoft Dynamics NAV Server instance is configured for.

    For an example of how to import data directly into a database, see the next step.

    Important

    To import an application, you must use the Import-NAVData cmdlet using the –DatabaseServer and –Database parameters, and you must make sure no users are accessing the database. Also, the database must be empty.

  4. To import an application directly into a Microsoft Dynamics NAV database, type the following command:

    Import-NAVData -DatabaseServer <server name> -Database <database name> -IncludeApplication -FilePath <location>
    

    For example, to run the cmdlet based on the data that you exported in the previous procedure, type the following command:

    Import-NAVData - DatabaseServer localhost -DatabaseName 'My Application Database' -IncludeApplication -FilePath c:\Data\myappanddata.navdata
    

    In the example, the database server is the local computer, the database is My Application Database, and the command imports the application objects that you exported from the CRONUS International Ltd. demonstration database. Because you want to import an application, you specify the –DatabaseServer and –DatabaseName parameters. If you want to import other types of data, you can choose to specify the –ServerInstance parameter as illustrated in the previous step. In a multitenant deployment, you must also specify the tenant database.

For another example of how to import companies and data, see the Example section.

Example

The following code example illustrates a Windows PowerShell script that you can use to export data from a Microsoft Dynamics NAV database and import data into another database.

Export-NAVData –ServerInstance ProductionServer –AllCompanies –FilePath MyFile.navdata |
Import-NAVData –ServerInstance TestServer -AllCompanies

In the example, you export all companies from the database in a production environment. You then import the companies into a database in a test environment. This example illustrates how you can use the Windows PowerShell cmdlets to copy data to a database for debugging or maintenance, for example.

See Also

Tasks

How to: Export and Import Companies and Other Data in Clients

Concepts

Exporting and Importing Companies and Other Data
Microsoft Dynamics NAV Windows PowerShell Cmdlets