PowerShell script to delete all files with a specific extension within a folder tree

A few weeks ago I was asked to empty the start menu of all Windows XP devices, and fill the start menu through Group Policy Preferences.
Since the last part has nothing to do with PowerShell, I’ll leave that one for your imagination… but cleaning all links from the start menu, or at least my solution, does.

The following command cleans all *.lnk files from the “C:\Documents and Settings” folder structure (so also from all underlying folders!):

Get-ChildItem “C:\Documents and Settings” -recurse -include *.lnk -force | remove-item

When you create a startup script through Group Policy and attach it to the devices, the start menu will be cleaned every time the computers starts. Since you can fill it at logon by using Group Policy Preferences, you will always offer a standardized start menu.

And just by changing the target and file extension you could use for just about any folder structure and file types Smile

Leave a Reply

Your email address will not be published. Required fields are marked *