Follow

How to remove old ProfileUnity logs from a directory with a command

Product: ProfileUnity-FlexApp

Product Version:  6.8.x

Expiration: 365 days from publishing

Updated: August 8, 2019

 

Problem:

Log directories can get cluttered and space can be wasted with old logs that are not needed anymore. Clearing logs after logon would save space and make easier to find most current logs.

Description:

How to clear logs from following directories:

%temp%\ProfileUnity

c:\Windows\Temp\ProfleUnity 

Resolution:

First Logs Location - (User Logs) This rule will clear any user logs that are older than 2 days. Chose one of the 4 rules listed here:

Option 1A) Create Application Launcher rule in ProfileUnity console configuration to clear logs after logon using ForFiles.exe:

  • Description: Clear User's %temp%\ProfileUnity logs
  • Filespec: ForFiles.exe
  • Arguments: /p "%temp%\ProfileUnity" /s /d -2 /c "cmd /c del @file"
  • Timing: After Configuration Execution
  • Run Asynchronously
  • Frequency: Every Logon

Option 1B) Create Application Launcher rule in ProfileUnity console configuration to clear logs after logon using powershell:

  • Description: Clear User's %temp%\ProfileUnity logs
  • Filespec: %systemroot%\system32\cmd.exe
  • Arguments: /c powershell.exe -NoProfile -executionpolicy bypass -command “Get-ChildItem $env:temp\ProfileUnity | Where-Object {$_.LastWriteTime -lt (Get-Date).AddDays(-2)} | Remove-Item -Recurse -Force -ErrorAction SilentlyContinue”
  • Timing: After Configuration Execution
  • Run Asynchronously
  • Frequency: Every Logon

Option 2A) Create User Defined Script rule in ProfileUnity console configuration to clear logs after logoff using ForFiles.exe:

  • Description: Clear User's %temp%\ProfileUnity logs
  • Execute: After ProfileUnity at Logoff (Post-Logoff)
  • Type: Executable:
  • File: ForFiles.exe /p "%temp%\ProfileUnity" /s /d -2 /c "cmd /c del @file"

Option 2B) Create User Defined Script rule in ProfileUnity console configuration to clear logs after logoff using powershell:

  • Description: Clear User's %temp%\ProfileUnity logs
  • Execute: After ProfileUnity at Logoff (Post-Logoff)
  • Type: Executable:
  • File: %systemroot%\system32\cmd.exe /c powershell.exe -NoProfile -executionpolicy bypass -command “Get-ChildItem $env:temp\ProfileUnity | Where-Object {$_.LastWriteTime -lt (Get-Date).AddDays(-2)} | Remove-Item -Recurse -Force -ErrorAction SilentlyContinue”

Second Logs Location - (System Logs) This Rule will clear any system logs that are older than 2 days. Chose one of the 4 rules listed here:

Option 1A) Create Application Launcher rule in ProfileUnity console configuration to clear logs after logon using ForFiles.exe:

  • Description: Clear System c:\windows\temp\ProfileUnity
  • Filespec: ForFiles.exe
  • Arguments: /p "C:\Windows\Temp\ProfileUnity" /s /d -2 /c "cmd /c del @file"
  • Timing: After Configuration Execution
  • Run Asynchronously
  • Frequency: Every Logon

Option 1B) Create Application Launcher rule in ProfileUnity console configuration to clear logs after logon using powershell:

  • Description: Clear System c:\windows\temp\ProfileUnity
  • Filespec: %systemroot%\system32\cmd.exe
  • Arguments: /c powershell.exe -NoProfile -executionpolicy bypass -command “Get-ChildItem C:\Windows\Temp\ProfileUnity | Where-Object {$_.LastWriteTime -lt (Get-Date).AddDays(-2)} | Remove-Item -Recurse -Force -ErrorAction SilentlyContinue”
  • Timing: After Configuration Execution
  • Run Asynchronously
  • Frequency: Every Logon

Option 2A) Create User Defined Script rule in ProfileUnity console configuration to clear logs after logoff using ForFiles.exe:

  • Description: Clear System C:\Windows\Temp\ProfileUnity
  • Execute: After ProfileUnity at Logoff (Post-Logoff)
  • Type: Executable:
  • File: ForFiles.exe /p "C:\Windows\Temp\ProfileUnity" /s /d -2 /c "cmd /c del @file"

Option 2B) Create User Defined Script rule in ProfileUnity console configuration to clear logs after logoff using powershell:

  • Description: Clear System C:\Windows\Temp\ProfileUnity
  • Execute: After ProfileUnity at Logoff (Post-Logoff)
  • Type: Executable:
  • File: %systemroot%\system32\cmd.exe /c powershell.exe -NoProfile -executionpolicy bypass -command “Get-ChildItem C:\Windows\Temp\ProfileUnity | Where-Object {$_.LastWriteTime -lt (Get-Date).AddDays(-2)} | Remove-Item -Recurse -Force -ErrorAction SilentlyContinue”

Note: If files are in use they will not be deleted. Modfy "2" to how many days back the logs will be omitted from deletion. 

Example:

mceclip0.png

Reference Document: https://winaero.com/blog/delete-files-older-x-days/ 

Was this article helpful?
2 out of 2 found this helpful
Have more questions? Submit a request

0 Comments

Article is closed for comments.