web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :

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

Roberto Stefanetti Profile Picture Roberto Stefanetti 12,998
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.

Example

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

Example

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.

#SERCH FOR STRING IN .AL FILES (WORKSPACE, APP)

#OPEN DIR, SUBDIR GET .AL FILES
#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

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

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

Example

Output to File

Output to Grid View

Share and Enjoy !

Shares

This was originally posted here.

Comments

*This post is locked for comments