Forum Discussion
eyalmargani
Nov 03, 2022Copper Contributor
DELETE USERS FILES FROM USER PROFILE BY GPO
hello , in my organization i need to delete all user's profiles files. i tried to it by gpo with the cmd script::del /f d:\user\%USERNAME%\documents\*.* del /f d:\user\%USERNAME%\Videos\*.* del ...
Leavii
Nov 09, 2022Brass Contributor
For my test no, the user was not an admin.
eyalmargani
Nov 10, 2022Copper Contributor
i write the following script :
del /q /f /s d:\user\%userprofile%\documents\*
del /q /f /s d:\user\%userprofile%\Videos\*
del /q /f /s d:\user\%userprofile%\Pictures\*
del /q /f /s d:\user\%userprofile%\Music\*
del /q /f /s d:\user\%userprofile%\Desktop\*
del /q /f /s d:\user\%userprofile%\Downloads\*
as i wrote before the user profile folder is at drive d.
it stil doesnt work.
any ideas?
del /q /f /s d:\user\%userprofile%\documents\*
del /q /f /s d:\user\%userprofile%\Videos\*
del /q /f /s d:\user\%userprofile%\Pictures\*
del /q /f /s d:\user\%userprofile%\Music\*
del /q /f /s d:\user\%userprofile%\Desktop\*
del /q /f /s d:\user\%userprofile%\Downloads\*
as i wrote before the user profile folder is at drive d.
it stil doesnt work.
any ideas?
- Impie1080Jul 20, 2023Copper Contributor
eyalmargani there seems to be a mistake in the paths. The %userprofile% environment variable should not be used with d:\user, as %userprofile% already contains the full path
del /q /f /s "%userprofile%\Documents\*"
del /q /f /s "%userprofile%\Videos\*"
del /q /f /s "%userprofile%\Pictures\*"
del /q /f /s "%userprofile%\Music\*"
del /q /f /s "%userprofile%\Desktop\*"
del /q /f /s "%userprofile%\Downloads\*" - LeaviiNov 10, 2022Brass Contributor
eyalmargani I would also recommend with any script you write to have a log of sorts when it isn't ran interactively. Something as simple as the below will go a long way. I also prefer to use powershell...
set "log=C:\users\public\delete-files.log" del /q /f /s %userprofile%\documents\* if %errorlevel% equ 0 ( ( echo Files deleted )>>%log% ) else ( ( echo Error: %errorlevel% )>>%log% )
- LeaviiNov 10, 2022Brass Contributor
eyalmargani %userprofile% is an environment variable and is the same as the user's profile path such as C:\users\eyalmargani\. You want either %userprofile%\Documents or what you had previously D:\users\%username%\documents\. You can open a cmd prompt and echo %userprofile%, and %username% to see what you get.