NAV Objects in NAV 2013 with NAV 2015 PowerShell Commendlets

NAV Objects in NAV 2013 with NAV 2015 PowerShell Commendlets
You can view NAV specific development commandlets by launching the development shell. To launch the Microsoft Dynamics NAV Development Shell, look for either the "Microsoft Dynamics NAV Development Shell" or the "Microsoft Dynamics NAV 2015 Development Shell" on the start menu. You will need to have the Development Environment (C/SIDE) option as part of your NAV install.  Dynamics NAV 2015's Development Shell now includes 6 new PowerShell Functions:  Function    Compile-NAVApplicationObject Function    Create-NAVDatabase Function    Delete-NAVApplicationObject Function    Export-NAVApplicationObject Function    Import-NAVApplicationObject Function    Invoke-NAVDatabaseConversion NOTE: The files referenced in this discussion are included toward the end of the document. New Power Shell functions included in Microsoft Dynamics NAV 2015's Development Shell
Figure 1 – New Power Shell functions included in Microsoft Dynamics NAV 2015's Development Shell Those functions don't exist in the 2013 or 2013 R2 Development Shell. View of function list from previous versions of Microsoft Dynamics NAV Development Shell
Figure 2 – View of function list from previous versions of Microsoft Dynamics NAV Development Shell It turns out these are PowerShell functions that utilize the finsql.exe export/import/compile/create database commands. In his blog posting, Merging Application Objects using Windows PowerShell in Microsoft Dynamics NAV 2015, Morten Jensen talks a little about these new function "wrappers".

Finsql.exe

Finsql.exe commands for reference:  Microsoft Dynamics NAV 2013 / NAV 2013 R2 Development Environment Commands for Microsoft Dynamics NAV 2013 Microsoft Dynamics NAV 2015 Development Envrionment Commands for Microsoft Dynamics NAV 2015

Ready to backport? 

Copy Microsoft.Dynamics.Nav.Ide.psm1 from a Dynamics NAV 2015 Install to your Dynamics NAV 2013 R2 directory. FROM HERE: C:Program Files (x86)Microsoft Dynamics NAV80RoleTailored Client TO HERE: C:Program Files (x86)Microsoft Dynamics NAV71RoleTailored Client Open Microsoft.Dynamics.Nav.Ide.psm1 with a text editor or the PowerShell ISE. First we need to update the $RtcKey. Update the Paths to Reflect a 2013 or R2 registry path. Comparison showing path differences for NAV 2013 and NAV 2015 (part 1)
Figure 3a – Comparison showing path differences for NAV 2013 Comparison showing path differences for NAV 2013 vs NAV 2015 (part 2)
Figure 3b – …vs NAV 2015 The NAV 2013 or 2013 R2 finsql.exe does not have a command parameter for skipping unlicensed objects. This will need to modified so the eventual $command variable does not include the ExportTxtSkipUnlicensed parameter.  #Original #$command = "Command=ExportObjects`,ExportTxtSkipUnlicensed=$skipUnlicensed`,File=`"$Path`"" #New $command = "Command=ExportObjects`,File=`"$Path`"" Modifying the command line parameter
Figure 4 – Modifying the command line parameter Now find C:Program Files (x86)Microsoft Dynamics NAV71RoleTailored ClientMicrosoft.Dynamics.Nav.Model.Tools.psd1 Change this line: # NestedModules = @() To this: NestedModules = @( 'Microsoft.Dynamics.Nav.Ide.psm1')  Modifying the value for NestedModules
Figure 5 – Modifying the value for NestedModules If we've edited everything correctly you should now have the new 2015 functions in your 2013/R2 Development Shell! Figure showing that the new Dynamics NAV 2015 functions are now available in the Dynamics NAV 2013/R2 Development Shell
Figure 6 – Figure showing that the new Dynamics NAV 2015 functions are now available in the Dynamics NAV 2013/R2 Development Shell Why are these PowerShell functions so neat? I can export out an entire Demo database’s objects and split into individual files in under a minute with a command line this: 
Import-Module "${env:ProgramFiles(x86)}Microsoft Dynamics NAV80RoleTailored ClientMicrosoft.Dynamics.Nav.Model.Tools.psd1" -force

Export-NAVApplicationObject C:ObjectExportAllObjects.txt -DatabaseServer 'localhost' -DatabaseName 'Demo Database NAV (8-0)' | Split-NAVApplicationObjectFile -Destination C:ObjectExport
Automating your common NAV development tasks can be a huge time saver.

Download the Files

I've included my files. I've also commented out two functions that aren't supported with NAV 2013 finsql.exe commands.  Microsoft.Dynamics.Nav.Ide.psm1 <- from 2015 contains the PowerShell wrapper functions. Microsoft.Dynamics.Nav.Model.Tools.psd1 <- Modified to import Microsoft.Dynamics.Nav.Ide.psm1  Execute Export-NAVApplicatonObject.ps1 <- My test of the functions on my 2013 R2 database.  NOTE: ArcherPoint is delighted to offer tips to developers throughout the NAV community, but code samples are not warranted, as all installations are different. It is advised that the developer verify that the solutions work for his or her installation of Dynamics NAV before implementing the code. If you have any further questions about this or other development questions, please contact one of our development experts at ArcherPoint. If you liked this, check out our collection of Development Blogs.

Trending Posts

Stay Informed

Choose Your Preferences
First Name
*required
Last Name
*required
Email
*required
Subscription Options
Your Privacy is Guaranteed