Zum Inhalt springen
PowerShell script to automate NAV tenant sync

Streamline NAV Tenant Synchronization with PowerShell

Daniel Gorski
Daniel Gorski 08. Juni 2023
1 Min. Lesezeit

Are you tired of manually rerunning powershell scripts when an error occurs? Like synchronizing your NAV (Navision) tenant and dealing with potential errors?

We've got a handy PowerShell try-catch example that will make your life easier.

This is just an example and you shouldn't drop your SQL tables ;-)

So handle with care.

Install-Module SqlServer
Import-Module "C:\\Program Files\\Microsoft Dynamics 365 Business Central\\140\\Service\\NavAdminTool.ps1"
Import-Module "C:\\Program Files\\Microsoft Dynamics 365 Business Central\\140\\Service\\Microsoft.Dynamics.Nav.Management.psd1"

$done = $false
while ($done -eq $false)
{
    try {
        Sync-NAVTenant –ServerInstance BC140 -tenant default -ErrorAction Stop -Force
        $done = $true
    }
    catch {
        $message = $_.Exception.Message
        $tablename = $message | Select-String -Pattern '\\"(.*\\$.*)\\"'
        $deleteQuery = 'drop table [dbo].['+$tablename.matches.groups[1]+']'
        Write-Host $deleteQuery
        #$done = $true
        if ($tablename.matches.groups[1].Value.contains('$')) {
            Invoke-Sqlcmd -ServerInstance SQLSERVER -Database DATABASENAME -Query $deleteQuery
        }
        else
        {
            Write-Error $message
            $done = $true
        }
    }
}

The script revolves around the Sync-NAVTenant cmdlet, which simplifies the synchronization of NAV tenants on a specified server instance.

To get started, simply copy the script into your PowerShell environment, adjust any necessary parameters, and execute it.

Enhance your NAV tenant management today with this powerful PowerShell script.

Experience the convenience and efficiency it brings to your daily operations.

Happy doing!

how-to
infrastructure
powershell
dynamics nav
navadmin
tenant sync
automation
E-Invoicing-Formate UBL, CII, ZUGFeRD und Factur-X im Vergleich

UBL, CII, ZUGFeRD, Factur-X: Die E-Invoicing-Formate endlich verständlich erklärt

UBL, CII, ZUGFeRD oder Factur-X – diese E-Invoicing-Formate werden ständig verwechselt. Wir erklären den Unterschied zwischen reinen XML-Formaten und Hybridform

Weiter lesen: UBL, CII, ZUGFeRD, Factur-X: Die E-Invoicing-Formate endlich verständlich erklärt
Weiter lesen: UBL, CII, ZUGFeRD, Factur-X: Die E-Invoicing-Formate endlich verständlich erklärt
E-Invoicing formats UBL, CII, ZUGFeRD and Factur-X compared

UBL, CII, ZUGFeRD, Factur-X: E-Invoicing Formats Finally Explained

UBL, CII, ZUGFeRD or Factur-X – these e-invoicing formats get confused all the time. We break down the difference between pure XML formats and hybrid PDF-plus-X

Weiter lesen: UBL, CII, ZUGFeRD, Factur-X: E-Invoicing Formats Finally Explained
Weiter lesen: UBL, CII, ZUGFeRD, Factur-X: E-Invoicing Formats Finally Explained