Tuesday, December 3, 2013

How to Delete File(s) with Similar Name from Different Users' Desktop?

If you want to manage file/shortcut on all the Win 7 Users' Desktops, you can always navigate to C:\Users\Public\Desktop or %AllUsersProfile% to delete or add the file/shortcut.

I want to use SCCM Task Sequence to delete some shortcuts with similar file name under different users' desktop today. I tried to Google around but most of the blog lead me to %userprofile% which delete the file/shortcut on the current logon user's desktop only

After google around, check with my script mater (Mr Brian Rayel) and testing, finally we able to delete files with similar names under different user desktops.

Option 1:
@echo off
cd C:\Users
for /d %%i in (*.*) do del %%i\Desktop\"Sample Of Shortcut*.lnk"

Option 2 (credit to my colleague, Master Brian Rayel):
@echo off
cd /d %windir%/../Users
for /f "delims=*" %%i in ('dir/b') DO del %%i\Desktop\"Sample Of Shortcut*.lnk" /q

It will remove all the shortcut start with Sample Of Shortcut*.lnk. For example, Sample Of Shortcut1.lnk, Sample Of Shortcut2.lnk and etc under different user's Desktop.

Happy trying. :)

No comments:

Post a Comment