Search for a string (or a TAG) in .al files with Powershell

Search for a string (or a TAG) in .al files with Powershell

Migrating, upgrading, recoding & refactoring the older versions of Dynamics NAV to Business Central you will (or can find) find a lot of documentation tracked both in the Documentation and development notes \ TAG sections within the code.

By loading these sources into Azure DevOps you can use the Microsoft built-in search function to find the strings \ tags of interest.

The same thing can be done by Powershell by reading inside the individual .al files with a few lines of code. it is possible to send the search on output filew or on gridview.

I publish the script because it could be useful to someone in certain situations, even if the changes are managed directly with Git and the DevOps tools with the new technologies for Business Central.


Microsoft Code Search for DevOps

With this integrated DevOps tool it is easy to search for strings in projects \ more projects \ REPOS.

Microsoft Code Search

Code Search in :

  • Full projects, single project, single REPO, multi REPO


Searching for string “DEV01

Windows Powershell Script

With this short windows powershell script I get the same thing by looking in the whole project, in a workspace, in the whole disk.


#Search parameters
$SearchString = ‘DEV01’  #CP=Customization part code example DEV01;  #VersionList=DEV01;IGM02;OIF23 etc.

#Log Folder path
$ObjectPathLog = ‘C:\Customer\Development\CPLOG\’
#CP Output file
$OutCPFile = ‘CPContent_’ + $SearchString + ‘.txt’
#Log Path file
$LogPath = Join-Path $ObjectPathLog $OutCPFile

#Master Directory
$MasterDir = ‘C:\Customer\Development\’

#Subfolders Search for .al files
$Subdir = Get-ChildItem -File -Recurse -Path $MasterDir -Include *.al
Write-Host $Subdir

#Read .al files
$myobjects = Get-ChildItem –Path $Subdir –Filter *.al -File
Write-Host $myobjects

#Output to Log file
$myobjects | Select-String $SearchString | Out-File -FilePath $LogPath -Append -Verbose -NoClobber

#Output to GridView
$myobjects | Select-String $SearchString | Out-GridView


Output to File

Output to Grid View

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.