The Clean-AXModel custom PowerShell function will allow you to clean up default AX layer models. Custom AX models allow you to use Uninstall-AXModel from the AxUtilLib.Powershell module to remove them from your environment but the default layer models (e.g. ‘USR Model’, ‘VAR Model’) will throw an error if you try to delete them. This is where Clean-AXModel will shine.
I use this function when preparing a non-production environment for a model push. In my environment, we only develop in one layer/model. It is possible that another developer has accidentally changed an object in another layer/model however. Clean-AXModel ensures that the only code that exists in my pre-production environments is the code that I’m going to bring in with my model push.
The Clean-AXModel function takes between 3 and 6 parameters:
- ConfigPath (Client configuration for the chosen AX environment)
- Model (The AX model to clean)
- TMPModel (The temporary model to move objects to. Defaults to ‘TMP Model’)
- Layer (The layer that holds the model to clean)
- AXVersion (The AX version. It defaults to 6.)
- NoInstallMode (A switch parameter that stops AX from prompting you to recompile when you log in after modifying the AXModelStore)
This function can be found in Codeplex. The steps of this function are:
- Get the AX environment info using Get-AXConfig
- Check to see if the model being cleaned has anything in it before cleaning it
- Delete the TMPModel if it already exists
- Move all objects from the model to clean into the TMPModel
- Delete the TMPModel
- Set “NoInstallMode” on the AX model database if the switch parameter was passed
I have updated the D2DDynamics module to version 1.0.5 with this function. I have also modified the Send-Email function with this changeset. I have fixed a bug that was brought up to me from a user regarding adding multiple “to” addresses to an email. This should now work.
This function has only be run by me on the AOS server. It has been tested using AX 2012 R2 CU6 and CU7 but I would expect this to work for any version of AX 2012.