AX2012 PowerShell commands

Here I'll start a collection of useful PowerShell commands:

Get-Content writes the content of a file to PowerShell window:
Get-Content c:\scripts\test.txt - wait

To get the last x lines use Select-Object - last x: (it might take some time :) )
Get-Content c:\scripts\test.txt | Select-Object -last 5

Microsoft Dynamics AX 2012 Management Shell

List Models

Get-AXModel -Config AOSName
Model Content:
(Get-AXModel -Model "USR Model" -Details).Elements | Out-String

Install / Uninstall a model

Install-AXModel -File Filename.axmodel -Config AOSName
Uninstall-AXModel -Database "NameOfDB" -Model "NameOfModel"

you could always use -Config AOSName or -Database "NameOfDB".

to overwrite existing elements in a model use -conflict: overwrite

Export a model

Export-AXModel –Model "NameOfModel" -File "FileName"

you could always use -Config AOSName or -Database "NameOfDB".

Export a modelstore

Export-AXModelStore -Config AOSName -File Filename.axmodelstore -Details

Import a modelstore

Stop the AOS for the import
Import-AXModelStore -Config AOSName -File Filename.axmodelstore

To reduce the downtime of the AOS the modelstore could be imported to a temporary schema 
Import-AXModelStore -File Filename.axmodelstore -SchemaName TemporarySchema

Drain all client connections from the AOS instance and apply the temporary schema
Import-AXModelStore -Apply:TemporarySchema -Config AOSName

SSRS Reports

Get a List of Reports starting with A and store it in a variable
$reports = Get-AXReport -ReportName A* -ServicesAOSWSDLPort 8109
To view the List

Deploy Reports:
Publish-AXReport -ReportName CustTransList -ServicesAOSWSDLPort 8109

No comments: