Dynamics Ax Management Shell powershell tips

Hi all,

When Dynamics Ax 2012 came out it was shipped with 2 tools AxUtil.exe and the Management shell. In my experience most of the Dynamics Ax developers are already familiar with AxUtil.exe but don’t have much experience in powershell yet. Therefor I decided to write some examples to get you guys going. If you have any questions or a request please leave a comment, I might also add some scripts as I go.

  1. # Load the Management utilities in to a standard powershell session
  2. # If you use the management shell you don't need this
  3. $dynamicsSetupRegKey = Get-Item "HKLM:\SOFTWARE\Microsoft\Dynamics\6.0\Setup"
  4. $sourceDir = $dynamicsSetupRegKey.GetValue("InstallDir")
  5. $dynamicsAXUtilPath = Join-path $sourceDir "ManagementUtilities\Microsoft.Dynamics.ManagementUtilities.ps1"
  6. .$dynamicsAXUtilPath
  7.  
  8. # List all the models like the AxUtil does
  9. Get-AXModel  | Sort-Object ModelId | Format-Table -Property ModelId,Layer,Name,DisplayName,Version -AutoSize
  10.  
  11. # List all the models like the AxUtil does but filter out the Sys and Syp
  12. Get-AXModel | Where {$_.Layer -NotLike "Sy*"}  | Sort-Object ModelId | Format-Table -Property ModelId,Layer,Name,DisplayName,Version -AutoSize
  13.  
  14. # Get all elements in a model file
  15. $models = Get-AXModel -File C:\Temp\model.axmodel -Details
  16. $models.Elements | Format-Table -Property Path

Leave a Reply

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