0

I currently have a simple batch file that deletes unnecessary cached data at log out for multiple workstations set as a GPO. I am trying to amend it to report back to me in one text doc every time this runs on the various workstations with the date as the name of the text doc and the name of the workstation and the user it was run for as the contents, (examples below).

Current Script Example:

Echo off
Del /f /s /q "C:\User\%username%\AppData\Local\Microsoft\OneNote\16.0\Backup"
Del /f /s /q "C:\User\%username%\AppData\Local\Microsoft\OneNote\16.0\Cache"
Del /f /s /q "C:\Users\%username%\AppData\Roaming\Microsoft\OneNote\16.0"

Requested Output Example:

File name: 20220815.txt contents:

UserName | Workstation 1 | Time
UserName | Workstation 2 | Time
Etc. 

File name: 20220816.txt contents:

UserName | Workstation 1 | Time
UserName | Workstation 2 | Time
Etc.

Any help would be greatly appreciated.

J.D
  • 1
  • 2
  • Sorry about that, This is done now. – J.D Aug 15 '22 at 14:15
  • I ran into a few other requirements as I was tooling around with it. – J.D Aug 15 '22 at 14:16
  • Sure Thing! One sec, I will edit it now – J.D Aug 15 '22 at 14:28
  • 1
    Those are directories, and `del`/`erase` does not delete directories, `rd`/`rmdir` does! Also, `C:\Users\%username%\AppData\Local` can be `%LocalAppData%`, and `C:\Users\%username%\AppData\Roaming` can be `%AppData%`. – Compo Aug 15 '22 at 14:43
  • Got it, thank you for the tip. The reason I went with the current syntax is that I simply need it to delete the contents of those folders without removing the folders themselves. I will absolutely use the shortening of the paths using your advice about the %LocalAppData% and %appdata% though, thank you!!! – J.D Aug 15 '22 at 16:29
  • If you want to delete files, use `del \*`. to create the textile, use `echo %username% ^| %computername% ^| %time% > file.txt`. To get the filename, use one of the answers to [this question](https://stackoverflow.com/questions/7727114/batch-command-date-and-time-in-file-name) (preferably one that does not depend on user settings, as they can be very individual) – Stephan Aug 15 '22 at 18:11

1 Answers1

0

This comment by Stephan what what I needed. The only thing I changed was

"echo %username% ^| %computername% ^| %time% > file.txt"

to

"echo %username% ^| %computername% ^| %time%>> file.txt"

so It can append the existing documents instead of creating a new one for every instance. Thank you!!!!

**

"If you want to delete files, use del *. to create the textile, use echo %username% ^| %computername% ^| %time% > file.txt. To get the filename, use one of the answers to this question (preferably one that does not depend on user settings, as they can be very individual) – Stephan 21 hours ago"

**

J.D
  • 1
  • 2