Using Windows Server 2012 R2:
My application creates many temp files in a service account's temp folder:
C:\Users\SVC_ACCT\AppData\Local\Temp\
I need to build a PowerShell script that cleans the content of the temp folder every night, outside of busy hours.
Before I build the script, I wonder if there is such command line that I can reliably schedule it every night?
Built-in app, yes and no, as powershell is now built-in, and is the reference to create such task. (use a
-WhatIf
on the line to test it before)With environment variables you can get temp directory of the user running the script:
Or, you can call CleanMgr.exe which can also clean up other things. This will need a wrapper script: Automate process of Disk Cleanup cleanmgr.exe without user intervention