Nov 03 2022 12:34 AM
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 /f d:\user\%USERNAME%Pictures\*.*
del /f d:\user\%USERNAME%\Music\*.*
del /f d:\user\%USERNAME%\Desktop\*.*
del /f d:\user\%USERNAME%\Downloads\*.*
unfortunatly its not working.
do you have another way to do so ?
thanks.
Nov 03 2022 07:15 AM
@eyalmargani You need to specify /q along with /f. I have tested the following and it works fine. Make sure your paths are correct, and the GPO is under User Configuration.
del /q /f /s %userprofile%\downloads\*
Nov 09 2022 06:21 AM
Nov 09 2022 06:28 AM
For my test no, the user was not an admin.
Nov 10 2022 07:13 AM
Nov 10 2022 07:28 AM
@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.
Nov 10 2022 07:36 AM - edited Nov 10 2022 07:39 AM
@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%
)
Jul 19 2023 09:21 PM
@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\*"