Clean up PSM rdp files in a users download folder via PowerShell script
93
Created On 11/10/26 10:59 AM - Last Modified 11/10/26 16:01 PM
Objective
This is a PowerShell script to clean up all of the "PSM Address.xxxxx" rdp files that are downloaded by a user, using PSM, to their downloads folder within the last 7 days.
Environment
10.5;10.10;11.1;11.2;11.3;11.4;11.5;11.6;11.7;12.0;12.1;12.2;12.6;13.0 Privileged Access Manager (PAM, self-hosted);Privilege Cloud PSM
Procedure
This can be run manually, or added to a GPO to be run on logoff. Simply save the below as a .ps1 file and run as required.
The parameters are set to delete rdp files that match the filter "*PSM Address*" created in the last 7 days located in the user's Downloads folder. These can easily be edited to match the customer use case.
# Set the path to the Downloads folder $downloadsPath = Join-Path $env:USERPROFILE "Downloads" # Get all files in the Downloads folder that match the filter "*PSM Address*" $files = Get-ChildItem -Path $downloadsPath -Filter "*.rdp" | Where-Object { $_.Name -like "*PSM Address*" } # Filter the files to only include those that were created in the last 7 days $files = $files | Where-Object {$_.CreationTime -gt (Get-Date).AddDays(-7)} # Delete the filtered files without any user prompt $files | Remove-Item -Force