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) usingStart 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:
CMDLETASSEMBLY
Edit-AXModelManifestAxUtilLib.PowerShell.dll
Export-AXModelAxUtilLib.PowerShell.dll
Export-AXModelStoreAxUtilLib.PowerShell.dll
Get-AXModelAxUtilLib.PowerShell.dll
Get-AXModelManifestAxUtilLib.PowerShell.dll
Grant-AXModelStoreAxUtilLib.PowerShell.dll
Import-AXModelStoreAxUtilLib.PowerShell.dll
Initialize-AXModelStoreAxUtilLib.PowerShell.dll
Install-AXModelAxUtilLib.PowerShell.dll
Move-AXModelAxUtilLib.PowerShell.dll
New-AXModelAxUtilLib.PowerShell.dll
Optimize-AXModelStoreAxUtilLib.PowerShell.dll
Set-AXModelStoreAxUtilLib.PowerShell.dll
Test-AXModelDataAxUtilLib.PowerShell.dll
Uninstall-AXModelAxUtilLib.PowerShell.dll
Add-AXEnterprisePortalClaimsAuthenticationProviderMicrosoft.Dynamics.Administration.dll
Add-AXSecurityRoleMemberMicrosoft.Dynamics.Administration.dll
Add-AXSharepointClaimsAuthenticationProviderMicrosoft.Dynamics.Administration.dll
Disable-AXUserMicrosoft.Dynamics.Administration.dll
Get-AXSecurityRoleMicrosoft.Dynamics.Administration.dll
Get-AXSecurityRoleInfoMicrosoft.Dynamics.Administration.dll
Get-AXSecurityRoleMemberMicrosoft.Dynamics.Administration.dll
Get-AXUserMicrosoft.Dynamics.Administration.dll
New-AXClaimsAwareEnterprisePortalServerMicrosoft.Dynamics.Administration.dll
New-AXSecurityRoleMicrosoft.Dynamics.Administration.dll
New-AXUserMicrosoft.Dynamics.Administration.dll
Remove-AXEnterprisePortalClaimsAuthenticationProviderMicrosoft.Dynamics.Administration.dll
Remove-AXSecurityRoleMicrosoft.Dynamics.Administration.dll
Remove-AXSharepointClaimsAuthenticationProviderMicrosoft.Dynamics.Administration.dll
Add-AXReportServerConfigurationMicrosoft.Dynamics.AX.Framework.Management.dll
Get-AXAOSMicrosoft.Dynamics.AX.Framework.Management.dll
Get-AXReportMicrosoft.Dynamics.AX.Framework.Management.dll
Get-AXReportDataSourceMicrosoft.Dynamics.AX.Framework.Management.dll
Get-AXReportServerConfigurationMicrosoft.Dynamics.AX.Framework.Management.dll
Publish-AXAssemblyMicrosoft.Dynamics.AX.Framework.Management.dll
Publish-AXReportMicrosoft.Dynamics.AX.Framework.Management.dll
Remove-AXReportServerConfigurationMicrosoft.Dynamics.AX.Framework.Management.dll
Set-AXReportDataSourceMicrosoft.Dynamics.AX.Framework.Management.dll
Set-AXReportServerConfigurationMicrosoft.Dynamics.AX.Framework.Management.dll
Test-AXReportServerConfigurationMicrosoft.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\60\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.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.