First steps with AX2012 Management Shell

Dynamics AX 2012 allows to perform and automate many administrative tasks by PowerShell. But how we can use each of such PowerShell commands (cmdlets)? I’m not going to describe that – instead I want to show how you can find it out by yourself.

PowerShell console for Dynamics AX can be run on a computer with Management utilities installed (that’s an option in AX2012 installer) using Start Menu > All Programs > Administrative Tools > Microsoft Dynamics AX 2012 Management Shell.

When console starts, imported assemblies are shown – these are what allows to call AX-specific cmdlets.

Now we need to know which commands are available. Let’s start with something simple – list all commands with “ax” in their names:

Get-Command *ax*

We get a long list with mixed cmdlets and other files. Let’s restrict the output to cmdlets only:

Get-Command *ax* -CommandType "Cmdlet"

That’s better. With a little more PowerShell magic we can show a list of all AX cmdlets and their containing assemblies:

Cmdlet Assembly
Edit-AXModelManifest AxUtilLib.PowerShell.dll
Export-AXModel AxUtilLib.PowerShell.dll
Export-AXModelStore AxUtilLib.PowerShell.dll
Get-AXModel AxUtilLib.PowerShell.dll
Get-AXModelManifest AxUtilLib.PowerShell.dll
Grant-AXModelStore AxUtilLib.PowerShell.dll
Import-AXModelStore AxUtilLib.PowerShell.dll
Initialize-AXModelStore AxUtilLib.PowerShell.dll
Install-AXModel AxUtilLib.PowerShell.dll
Move-AXModel AxUtilLib.PowerShell.dll
New-AXModel AxUtilLib.PowerShell.dll
Optimize-AXModelStore AxUtilLib.PowerShell.dll
Set-AXModelStore AxUtilLib.PowerShell.dll
Test-AXModelData AxUtilLib.PowerShell.dll
Uninstall-AXModel AxUtilLib.PowerShell.dll
Add-AXEnterprisePortalClaimsAuthenticationProvider Microsoft.Dynamics.Administration.dll
Add-AXSecurityRoleMember Microsoft.Dynamics.Administration.dll
Add-AXSharepointClaimsAuthenticationProvider Microsoft.Dynamics.Administration.dll
Disable-AXUser Microsoft.Dynamics.Administration.dll
Get-AXSecurityRole Microsoft.Dynamics.Administration.dll
Get-AXSecurityRoleInfo Microsoft.Dynamics.Administration.dll
Get-AXSecurityRoleMember Microsoft.Dynamics.Administration.dll
Get-AXUser Microsoft.Dynamics.Administration.dll
New-AXClaimsAwareEnterprisePortalServer Microsoft.Dynamics.Administration.dll
New-AXSecurityRole Microsoft.Dynamics.Administration.dll
New-AXUser Microsoft.Dynamics.Administration.dll
Remove-AXEnterprisePortalClaimsAuthenticationProvider Microsoft.Dynamics.Administration.dll
Remove-AXSecurityRole Microsoft.Dynamics.Administration.dll
Remove-AXSharepointClaimsAuthenticationProvider Microsoft.Dynamics.Administration.dll
Add-AXReportServerConfiguration Microsoft.Dynamics.AX.Framework.Management.dll
Get-AXAOS Microsoft.Dynamics.AX.Framework.Management.dll
Get-AXReport Microsoft.Dynamics.AX.Framework.Management.dll
Get-AXReportDataSource Microsoft.Dynamics.AX.Framework.Management.dll
Get-AXReportServerConfiguration Microsoft.Dynamics.AX.Framework.Management.dll
Publish-AXAssembly Microsoft.Dynamics.AX.Framework.Management.dll
Publish-AXReport Microsoft.Dynamics.AX.Framework.Management.dll
Remove-AXReportServerConfiguration Microsoft.Dynamics.AX.Framework.Management.dll
Set-AXReportDataSource Microsoft.Dynamics.AX.Framework.Management.dll
Set-AXReportServerConfiguration Microsoft.Dynamics.AX.Framework.Management.dll
Test-AXReportServerConfiguration Microsoft.Dynamics.AX.Framework.Management.dll

Concretely, I used this script:

Get-Command *ax* -CommandType "Cmdlet"
| Select-Object Name,@{Name="Assembly"; Expression={Split-Path $_.DLL -Leaf}}
| Sort-Object Assembly,Name

Now it’s apparent why these assemblies are imported when Management Shell starts.

There is another related problem: If you save your PowerShell code to a (.ps1) file a run it, the normal PowerShell (without assemblies mentioned above) is used, and AX cmdlets calls naturally fail. The easiest solution is to run the import in the same manner as AX2012 Management Shell does. Just add the following command at the beginning of your script:

. "C:\Program Files\Microsoft Dynamics AX\ManagementUtilities\Microsoft.Dynamics.ManagementUtilities.ps1"

Now we know available commands, but we still don’t know how to use them. And that’s why we have… a help. Just call Get-Help with  a name of some cmdlet. For example:

Get-Help Move-AXModel #or also "Move-AXModel -?"

shows this help:

NAME
    Move-AXModel

SYNOPSIS
    Moves the content from one model in the Microsoft Dynamics AX model store to another model in the same layer.

SYNTAX
    Move-AXModel [-TargetModel]  [[-Config] ] [-Confirm] [-WhatIf] []

    Move-AXModel [-TargetModel]  [[-Database] ] [[-Server] ] [-Confirm] [-WhatIf] []

    Move-AXModel [-Model]  [-TargetModel]  [-Confirm] [-WhatIf] []

    Move-AXModel [-ManifestFile]  [-TargetModel]  [-Confirm] [-WhatIf] []

DESCRIPTION
    The Move-AXModel cmdlet enables you to move the content from one model in the Microsoft Dynamics AX model store
     to another model in the same layer.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=217565
    New-AXModel 

REMARKS
    To see the examples, type: "get-help Move-AXModel -examples".
    For more information, type: "get-help Move-AXModel -detailed".
    For technical information, type: "get-help Move-AXModel -full".

Notice also additional options in the Remarks section, e.g. get-help Move-AXModel -detailed.

That’s almost everything you need to know about cmdlets for Dynamics AX 2012. Nevertheless, using of PowerShell is much wider topic – you can start here, for example, if you’re interested.