Dynamics AX 2012 R3 CMD

As the administrator of Dynamics AX likes to save time for recurring/repetitive tasks, I found a way to automize some of the deployment tasks. To get the best performance while executing these tasks, I take my resort to the DOS prompt. The command line tools I use are axutil and axbuild, and some command line startup commands that can be passed when starting the Client application.

Axutil is used to import and export, or even delete, models from Dynamics AX 2012 R3. When the modelstore needs an update, Axbuild is used to compile the complete environment. The database structure can be updated with a database synchronization.

The following are example batch files for the actions mentioned above.

Use the examples at your own risk! And change the settings accordingly to your situation!

Create-model.bat

@ECHO OFF
REM Author: byteway
REM Description: Create Dynamics AX Model

SET AXUTIL="c:\\Program Files\\Microsoft Dynamics AX\\60\\Server\\MicrosoftDynamicsAX\\bin\\AXUtil.exe"
SET MODELNAME="%~1" 

IF %MODELNAME%=="" GOTO DONOTHING
GOTO DOCREATE

:DOCREATE
%AXUTIL% create /model:"%MODELNAME%" /layer:"USR"
GOTO END

:DONOTHING
ECHO No modelname found!
ECHO Example: "create-model.bat 'TEST'"
GOTO END

:END
pause

Export-model.bat

@ECHO OFF
REM Author: byteway
REM Description: Export Dynamics AX Model

SET AXUTIL="c:\\Program Files\\Microsoft Dynamics AX\\60\\Server\\MicrosoftDynamicsAX\\bin\\AXUtil.exe"
SET MODELNAME=%~1 
SET OUTPUTFOLDER=%~2
SET COUNTER=1

IF %MODELNAME%=="" GOTO NOMODELNAME
IF %OUTPUTFOLDER%=="" GOTO NOOUTPUTFOLDER
GOTO LOOPFILENAME

:LOOPFILENAME
if exist "%OUTPUTFOLDER%%MODELNAME%(%COUNTER%).axmodel" set /a COUNTER+=1 && GOTO :LOOPFILENAME
SET OUTPUTFILE="%OUTPUTFOLDER%%MODELNAME%(%COUNTER%).axmodel"
GOTO DOEXPORT

:DOEXPORT
%AXUTIL% export /model:%MODELNAME% /file:%OUTPUTFILE%
GOTO END

:NOMODELNAME
ECHO No modelname found!
ECHO Syntax: export-model.bat "modelname" "output folder"
ECHO Example: "export-model.bat 'TEST' 'c:\Temp\'"
GOTO END

:NOOUTPUTFOLDER
ECHO No output folder found!
ECHO Syntax: export-model.bat "modelname" "output folder"
ECHO Example: "export-model.bat 'TEST' 'c:\\Temp\\'"
GOTO END

:END
pause

Remove-model.bat

@ECHO OFF
REM Author: byteway
REM Description: Delete Dynamics AX Model

SET AXUTIL="c:\\Program Files\\Microsoft Dynamics AX\\60\\Server\\MicrosoftDynamicsAX\\bin\\AXUtil.exe"
SET MODELNAME="%~1" 

IF %MODELNAME%=="" GOTO DONOTHING
GOTO DODELETE

:DODELETE
%AXUTIL% delete /model:"%MODELNAME%"
GOTO END

:DONOTHING
ECHO No modelname found!
ECHO Example: "remove-model.bat 'TEST'"
GOTO END

:END
pause

Compile-all.bat

@ECHO OFF
REM Author: byteway
REM Description: Recompile Dynamics AX

SET AXBUILD="c:\\Program Files\\Microsoft Dynamics AX\\60\\Server\\MicrosoftDynamicsAX\\bin\\AXBuild.exe"

REM First restart the Application Object Server
net stop MSSQLSERVER
net stop AOS60$01
net start MSSQLSERVER
net start AOS60$01

REM Second start compilation threads
cd "c:\\Program Files\\Microsoft Dynamics AX\\60\\Server\\MicrosoftDynamicsAX\\bin\\"
%AXBUILD% xppcompileall /workers=8 /s=01

pause

Synchronize.bat

@ECHO OFF
REM Author: byteway
REM Description: Synchronize the Dynamics AX database

SET AX32="c:\\Program Files (x86)\\Microsoft Dynamics AX\\60\\Client\\Bin\\Ax32.exe"

REM Synchronize the DB
%AX32% -lazyclassloading -lazytableloading -StartupCmd=Synchronize

pause