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

How-To Split C/AL Objects Using PowerShell

Daniel Gorski
Daniel Gorski March 03, 2021
1 min read

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:

The Split-Objects.ps1 script in VS Code with both the slow (#slow) and fast (#fast) Measure-Command variants

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:

Terminal output comparing the two functions' run times, about 43.8 seconds for the slow version versus 5.26 seconds for the fast version

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

Related posts

▸ All posts
TXT2AL conversion guide

How-To Solve your issues after TXT2AL

February 24, 2021 · Daniel Gorski

Learn how to fix common issues after converting C/AL to AL using TXT2AL – with regex, PowerShell scripts, and hands-on troubleshooting tips.

Read More
Read More: How-To Solve your issues after TXT2AL
Fixing DNS issues in Docker Containers

Docker DNS Not Working in Windows Containers

June 13, 2025 · Malte Petersen

Docker container can't resolve host names? Set a DNS server inside the Windows container, or once for all containers in daemon.json. Two fixes.

Read More
Read More: Fixing DNS Issues in Windows-Based Docker Containers for Business Central Testing
PowerShell script to automate NAV tenant sync

Auto-Retry NAV Tenant Sync with PowerShell

June 08, 2023 · Daniel Gorski

Failed NAV tenant syncs no longer need a manual rerun: this PowerShell script with try-catch handling retries the synchronization automatically.

Read More
Read More: Streamline NAV Tenant Synchronization with PowerShell