©2019 by Neil Roberts. Proudly created with Wix.com

  • Neil Roberts

Using Powershell in Microsoft AL for Business Central (OnPrem)


Mark Brummel created an extension for Business Central Wave 2 (v15), which allows a user to view the license information of the license that has been uploaded to Business Central (OnPrem).


At the end of his post he put up a challenge, stating that he would like someone to add the ability to upload a license into Business Central from his License Information Extension.


So I decided to take on the challenge, because I remember reading something on mibuso.com about using powershell within Microsoft Dynamics NAV 2017.


This is what I used for my base to create the license upload functionality.

  • The first thing that I needed to do was to create a dotnet.al file to be able to use the PowerShellRunner.dll within the extension.

  • The next thing I created was a codeunit to handle the upload of the license file from the client to the server, as well as making the use of the PowershellRunner to run a specific command to import the license file.


What does this functionality do?

  • It allows you to select the license file from your machine (client side).

  • In the background it uploads the selected file to the service tier (server side).

  • PowerShellRunner then imports the NAVAdminTool module, so that it can use the 'Import-NAVServerLicense' script to import the license.

  • It then adds the necessary parameters required for the 'Import-NAVServerLicense' script, which is the ServerInstance (eg. BC) and the LicenseFile location.

  • It will then invoke the script as defined, which in turn imports the license into the database.


Conclusion

This was a great challenge as I had the opportunity to convert something that had already been used in Microsoft Dynamics NAV in C/AL and make it work for Business Central.


All of the code can be found on my GitHub.


Enjoy!