Recursively remove desktop.ini files Recursively remove desktop.ini files powershell powershell

Recursively remove desktop.ini files


del /s /a desktop.ini

See del /? for help.


This is what I used for Windows 2012 server

Create Desktop.ini files

My desktop.ini files were created from running this script which sets default folder options

$key = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced'Set-ItemProperty $key Hidden 1Set-ItemProperty $key HideFileExt 0Set-ItemProperty $key ShowSuperHidden 1Stop-Process -processname explorer

Remove Desktop.ini files

# Remove from your user desktopgci "$env:USERPROFILE\Desktop" -filter desktop.ini -force | foreach ($_) {remove-item $_.fullname -force}# Remove from default desktopgci "C:\Users\Public\Desktop" -filter desktop.ini -force | foreach ($_) {remove-item $_.fullname -force}


I had a similar problem and here is my solution:

Get-Location | Get-ChildItem -Force -Recurse -File -Filter "desktop.ini" | Remove-Item

The first part gets the current active directory.

Get-Location

You could replace it with a path like:

"C:\Users\Chris" | Get-ChildItem -Force -Recurse -File -Filter "desktop.ini" | Remove-Item

The second part gets child items in the path.

Get-ChildItem -Force -Recurse -File -Filter "desktop.ini"
  • -Force -> force seeing all child items even hidden ones, most "desktop.ini" are hidden
  • -Recurse -> to be recursive
  • -File -> to get only files else it could find a folder named "desktop.ini"
  • -Filter "desktop.ini" -> to only get items named "desktop.ini"

The last part removes the item.

Remove-Item

Adding a -WhatIf for the first run may be safer.

Remove-Item -WhatIf