AX2012 Management Shell如何使用



AX2012 Management Shell是一个非常强大的工具, 该如何使用呢?网上找到Martin Dráb写的一篇文章指导如何使用这个工具。


原文来自: http://dev.goshoom.net/en/2011/10/ax2012-powershell-en/


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:

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值