Im trying to cleanup old images in my ACR. It has 8 repositories so first I want it to test it in only one of them... The complicated thing about it that I need to keep last 4 images created. So I have this script:

$acrName = ACRttestt

$repo = az acr repository list --name $acrName --top 1

$repo | Convertfrom-json | Foreach-Object { $imageName = $_ (az acr repository show-tags -n $acrName --repository $_ | convertfrom-json |) Select-Object -SkipLast 4 | Foreach-Object { az acr repository delete -n $acrName --image "$imageName:$_" } }

But Im receiving the following error:

Failed At line:9 char:58 + ... az acr repository delete -n $acrName --image "$imageName:$_" + ~~~~~~~~~~~ Variable reference is not valid. ':' was not followed by a valid variable name character. Consider using ${} to delimit the name.

Any ideas?

Thanks in advance

closed as off-topic by Izzy Sep 11 at 22:48

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

Browse other questions tagged or ask your own question.