Hello @Mishra, Rajiv ,
There should be some criteria based upon which you are deciding the latest 3 images , right ?
What is your criteria ? Like how are you identifying that 3 images are latest ? Is it by tagging ? Is it by version number ? Is it by last access date ?
So try to stick with one of the pattern , then you should be able to tweak that filter options for sure in acr purge. There are multiple options in the filter and also you can specify regular expressions
Couple of additional docs:
https://pixelrobots.co.uk/2020/02/purge-container-images-from-azure-container-registry-acr-on-demand-or-on-a-schedule/
One of the custom option is to write a script (which you already have it) and schedule the JOB on the Azure VM. There are multiple .ps1 scripts in the below github. [ You can use SP for authentication]
(If you don't want the Azure VM to run 24x7 to save costs, you can use the RunBooks , Auto Start/Shutdown options - You can schedule the VM to Start-Up once a day , let the schedule script run once - once the script executes - automatically shutdown the VM)
https://github.com/goyalmohit/acr-cleanup
If either of those answers are helpful to you , Kindly make sure to "Accept Answer" so that It will be a value addition for the whole community out there.