Delete GUID named files in folders


Hi All,

Want to delete the GUID named files in your folders?

Here is the simple script that takes the regex for GUID and compares the file name and remove it.

get-childitem |? {$_.basename -match("^(\{){0,1}[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}(\}){0,1}$")} |Remove-Item

if you want to Include subfolders too, use the recurse option like below

get-childitem -Recurse |? {$_.basename -match("^(\{){0,1}[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}(\}){0,1}$")} |Remove-Item

Note: please test it in lower environments before implementing in production.

Regards,

Chaitanya

Leave a comment

Design a site like this with WordPress.com
Get started