I apologize for missing last week’s post but I’m in the process of moving and my free time has all but gone away. I discovered the idea for this PowerShell function from a couple of different places. I first saw the concept of cleaning up “artifact” files in the Build and Deploy Scripts for Microsoft Dynamics AX but I found it much more detailed in the Dynamics AX Admin Utilities. I was interested in this because I missed the “default fix” that was deleting the application object index in earlier versions of AX. This isn’t quite the same but it does remove the files that AX generates and stores on the client and server, forcing AX to re-deploy them from code.
The Clean-AXArtifacts function takes between 0 and 3 parameters:
- ConfigPath (Client configuration for the chosen environment)
- CleanServer (Switch parameter used to clean artifact files on the server)
- AllUsers (Switch parameter used to clean artifact files for all users on the client instead of just the current user)
The ConfigPath parameter is only required if the CleanServer parameter is used. The CleanServer parameter will stop the AOS (if it’s running), delete the server artifacts and start the AOS (if it was stopped by the function earlier). AllUsers is good for terminal server client servers. It will allow you to delete the client artifacts for all users that log onto that terminal server.
This function can be found in Codeplex. This function also uses 2 internal functions that I’ve created, Clean-Folder and Clean-Folders. These functions allow me to loop through the folders and delete the files. The steps of this function are:
- Validate parameters
- Check if the server needs to be cleaned
- Get the AX environment info using Get-AXConfig
- Stop the AOS if it’s running
- Delete the server artifact files using Clean-Folder
- Start the AOS if it was stopped by the function
- Check if all users need to be cleaned
- Use Clean-Folders for all users or Clean-Folder if not
I use this function during builds and also during pushes. When I have an environment that has more than one AOS, I generally stop the AOS on the other AOS’s, then run Clean-AXArtifacts on the primary AOS. While it is running, I log onto the other AOS’s and run the function there. I also log onto the client terminal server and delete the client artifacts for all users. When the primary AOS has started again, I start the AOS’s on the other AOS servers. This function has become my default AOS bounce. Instead of restarting the AOS, I call Clean-AXArtifacts.
Like all of my other functions, this must be run on the server that you are deleting files on.