Tag: RDS

Clearing AX Client Cache for All Users on a RDS Host

Clearing AX Client Cache for All Users on a RDS Host

It’s AX code update time, and you’re needing to clear out everyone’s AX client side cache on your RDS host servers.

That’s a lot of user folders to do through.

Here’s what I do:

Let’s start with some assumptions.

  1. You have the AX client deployed using Remote Desktop Services (RemoteAPP)
  2. You are not using User Profile Disks

If that describes your environment, read on.  If not, or if it’s close, keep reading.  You may be able to modify my solution to fit your needs.

The goal:  Remove all local AX cache files for all users in the following locations:

  1. All files/folders starting with “vsa” located here: c$\users\%username%\Appdata\Local\Microsoft\Dynamics AX\
  2. All files ending in “*.kti” or “.auc” located here: c$\users\%username%\Appdata\Local

Requirements:

  1. User running the Powershell script must have full rights to each user folder on each RDS host server.  Domain Admin members in AD would be a good place to start for the quick and dirty way.
  2. You must run this on each RDS host server.

What it does:

  1. Users the command “get-childitem” under “c:\users” to generate a list of all folders
  2. Using “foreach”, it loops through every folder
  3. In each folder, it does a “get-item” under the specific AX client cache directories get all files/folders, then another “for-each” to delete them

The code:

#Specify Directory containing User folders
$userfolderlist = get-childitem -path c:\users -directory

#Remove AX Client Cache files for each folder
foreach ($item in $userfolderlist)
{
write-host "Removing Test AX cache for username $item"
            get-item "C:\Users\$item\AppData\Local\Microsoft\Dynamics Ax\vsa*" | foreach ($_) {remove-item $_.fullname -recurse}
            get-item "C:\Users\$item\AppData\Local\*.kti" | foreach ($_) {remove-item $_.fullname -recurse}
            get-item "c:\Users\$item\AppData\Local\*.auc" | foreach ($_) {remove-item $_.fullname -recurse}
            }

***DISCLAIMER*** I am not responsible for this breaking or damaging any of your stuff.  Copyrights belong to their original owners***

Clearing AX Client Cache for One User in a RDS Environment Using Powershell

Clearing AX Client Cache for One User in a RDS Environment Using Powershell

“You should clear that person’s AX cache”.

How many times have you heard that?  If you are running Dynamics 2012 (R2 in my case), this post may help.

Let’s start with some assumptions.

    1. You have the AX client deployed using Remote Desktop Services (RemoteAPP)
    2. You are not using User Profile Disks
    3. You have multiple RDS Hosts people connect to

If that describes your environment, read on.  If not, or if it’s close, keep reading.  You may be able to modify my solution to fit your needs.

The goal:  Remove all local AX cache files for one user in the following locations:

  1. All files/folders starting with “vsa” located here: \\%hostname%\c$\users\%username%\Appdata\Local\Microsoft\Dynamics AX\
  2. All files ending in “*.kti” or “.auc” located here: \\%hostname%\c$\users\%username%\Appdata\Local
  3. Additionally, be able to do this for Production, Test, Dev, and Training AX RDS servers

Requirements:  User running the Powershell script must have full rights to each user folder on each RDS host server.  Domain Admin members in AD would be a good place to start for the quick and dirty way.

What it does:

  1. Prompts the person to enter the AD username of the desired user of whose cache you want cleared (line 5)
  2. Prompts the person to make sure that user has had their RDS session closed, otherwise the AX client may still be running, thus locking the files you want to delete (line 6)
  3. Asks if you are sure (line 8).  If you enter Y, the script continues, otherwise a N will skip over everything until line 64.
  4. Asks which AX environment you want to do this in (line 13)
  5. Connects to the RDS server for the environment specified in step 4.

There are if/else statements from here on out (line 17, 24, 31, and then 38) that are hard coded for specific servers dependent on which AX environment you chose.

The code:

#This script will connect to AX RDS servers and delete the AX client cache
#Make sure the user has been logged out of the RDS box first otherwise the files will be locked

#Provide the Active Directory Username
$axuser = read-host 'Enter the AD username'
write-host "Make sure that $axuser has been logged out of their RDS session before proceeding"

$Yousure = read-host 'Are you sure you want to continue? Y/N'
If ($yousure -match "y")
 {

#Provide the AX Environment
write-host "Possible AX Environments:  Test, Training, Dev, Prod"
$axenvironment = read-host 'Enter the AX Environment'
    
#Connect to AX environment chosen and delete local cache    
    If ($axenvironment -match "Test")
        {
            write-host "Removing Test AX cache for username $axuser"
            get-item "\\axtestrds\c$\Users\$axuser\AppData\Local\Microsoft\Dynamics Ax\vsa*" | foreach ($_) {remove-item $_.fullname -recurse} 
            get-item "\\axtestrds\c$\Users\$axuser\AppData\Local\*.kti" | foreach ($_) {remove-item $_.fullname -recurse} 
            get-item "\\axtestrds\c$\Users\$axuser\AppData\Local\*.auc" | foreach ($_) {remove-item $_.fullname -recurse}
        }
        else { If ($axenvironment -match "Training")
            {
                write-host "Removing Training AX cache for username $axuser"
                get-item "\\TrainingRDS\c$\Users\$axuser\AppData\Local\Microsoft\Dynamics Ax\vsa*" | foreach ($_) {remove-item $_.fullname -recurse} 
                get-item "\\TrainingRDS\c$\Users\$axuser\AppData\Local\*.kti" | foreach ($_) {remove-item $_.fullname -recurse } 
                get-item "\\TrainingRDS\c$\Users\$axuser\AppData\Local\*.auc" | foreach ($_) {remove-item $_.fullname -recurse } 
            }
                else { If ($axenvironment -match "Dev")
                    {
                        write-host "Removing Dev AX cache for username $axuser"
                        get-item "\\DevRDS\c$\Users\$axuser\AppData\Local\Microsoft\Dynamics Ax\vsa*" | foreach ($_) {remove-item $_.fullname -recurse } 
                        get-item "\\DevRDS\c$\Users\$axuser\AppData\Local\*.kti" | foreach ($_) {remove-item $_.fullname -recurse } 
                        get-item "\\DevRDS\c$\Users\$axuser\AppData\Local\*.auc" | foreach ($_) {remove-item $_.fullname -recurse } 
                    }
                    else { If ($axenvironment -match "Prod")
                        {
                            write-host "Removing Prod AX cache for username $axuser"
                            get-item "\\ProdRDS02\c$\Users\$axuser\AppData\Local\Microsoft\Dynamics Ax\vsa*" | foreach ($_) {remove-item $_.fullname -recurse} 
                            get-item "\\ProdRDS02\c$\Users\$axuser\AppData\Local\*.kti" | foreach ($_) {remove-item $_.fullname -recurse} 
                            get-item "\\ProdRDS02\c$\Users\$axuser\AppData\Local\*.auc" | foreach ($_) {remove-item $_.fullname -recurse} 
                            get-item "\\ProdRDS03\c$\Users\$axuser\AppData\Local\Microsoft\Dynamics Ax\vsa*" | foreach ($_) {remove-item $_.fullname -recurse} 
                            get-item "\\ProdRDS03\c$\Users\$axuser\AppData\Local\*.kti" | foreach ($_) {remove-item $_.fullname -recurse} 
                            get-item "\\ProdRDS03\c$\Users\$axuser\AppData\Local\*.auc" | foreach ($_) {remove-item $_.fullname -recurse} 
                            get-item "\\ProdRDS04\c$\Users\$axuser\AppData\Local\Microsoft\Dynamics Ax\vsa*" | foreach ($_) {remove-item $_.fullname -recurse} 
                            get-item "\\ProdRDS04\c$\Users\$axuser\AppData\Local\*.kti" | foreach ($_) {remove-item $_.fullname -recurse } 
                            get-item "\\ProdRDS04\c$\Users\$axuser\AppData\Local\*.auc" | foreach ($_) {remove-item $_.fullname -recurse } 
                            get-item "\\ProdRDS05\c$\Users\$axuser\AppData\Local\Microsoft\Dynamics Ax\vsa*" | foreach ($_) {remove-item $_.fullname -recurse} 
                            get-item "\\ProdRDS05\c$\Users\$axuser\AppData\Local\*.kti" | foreach ($_) {remove-item $_.fullname -recurse } 
                            get-item "\\ProdRDS05\c$\Users\$axuser\AppData\Local\*.auc" | foreach ($_) {remove-item $_.fullname -recurse } 
                            get-item "\\1075rds09\c$\Users\$axuser\AppData\Local\*.auc" | foreach ($_) {remove-item $_.fullname -recurse} 
                            }
                                else { write-host "You did not enter the right command"
                                    }
                        }
                    }
                }

#Reminder to clear usage data in AX Client
write-host "Now that cache has been cleared, connect to AX client on $axenvironment and clear the usage data for $axuser"
}
else 
                    {write-host "You chose not to continue.  Well played"
                    }

***DISCLAIMER*** I am not responsible for this breaking or damaging any of your stuff.  Copyrights belong to their original owners***