Skip to content
Split legacy NAV/Business Central object files with PowerShell

How-To Split C/AL Objects Using PowerShell

Daniel Gorski
Daniel Gorski 03. März 2021
1 Min. Lesezeit

You want to split your objects by using a simple PowerShell script?

You can use this module:
Microsoft.Dynamics.Nav.Model.Tools
with the command Split-NAVApplicationObjectFile

No matter which version of Navision, Dynamics NAV or Business Central in C/AL you are using:

I've built a slow and fast variant ;-) so don't get confused.

#fast

$sourcepath = "D:\Source\"
$targetpath = "D:\Target\"
Remove-Item $targetpath\*.txt -Recurse -Force

Measure-Command -Expression {
  Get-ChildItem $sourcepath -Filter *.txt | ForEach-Object {
    $filepath = $_.FullName
    $lines = Get-Content -Path $filepath
    foreach ($line in $lines) {
      if ($line -match "OBJECT (Table|Report|Codeunit|Page|Query|XMLport|Form|Dataport|MenuSuite) (\d+) (.*)") {
        if ($newfilepath) {
          $arr | Out-File -Append $newfilepath -Encoding default
          $arr = @()
        }
        $newfilepath = (Join-Path -Path $targetpath -ChildPath (
          $Matches[1].ToLower() + '_' + ('{0:d10}' -f [int]$Matches[2]) + $_.Extension
        ))
      }
      $arr += $line
    }
  }
}

And see how fast these two functions are:

Get the script here: Split-Objects.ps1
https://github.com/byndit/UsefulScripts/tree/main/Powershell

how-to
automation
powershell
business central
dynamics nav
legacy development
txt2al
GoBD-konforme Archivierung mit Business Central und SharePoint ohne DMS

Architektur

Revisionssicher archivieren ohne DMS? Wie weit Business Central, SharePoint und Azure Blob Storage wirklich tragen

Warum „GoBD" oft vorschnell zum K.O.-Kriterium wird – und wie weit Business Central, SharePoint und Azure Blob Storage wirklich tragen.

Read More: Revisionssicher archivieren ohne DMS? Wie weit Business Central, SharePoint und Azure Blob Storage wirklich tragen
Read More: Revisionssicher archivieren ohne DMS? Wie weit Business Central, SharePoint und Azure Blob Storage wirklich tragen
Modulare ERP-Architektur für skalierbare Unternehmenssoftware

Architektur

Mehr als nur Warenwirtschaft - die Landtechnik Lösung

ERP-Systeme wurden jahrelang als Monolithen verkauft. Die eigentliche Stärke moderner Plattformen wie Business Central liegt jedoch in der Modularität - und gen

Read More: Mehr als nur Warenwirtschaft - die Landtechnik Lösung
Read More: Mehr als nur Warenwirtschaft - die Landtechnik Lösung