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 standard directories for logs used by ProfileUnity by default:
%temp%\ProfileUnity
c:\Windows\Temp\ProfleUnity
Resolution(s):
Solution1:
Use the CMD.exe for the filespec, but change the arguments to
FileSpec: %systemroot%\System32\cmd.exe
Arguements: /c powershell.exe -executionpolicy bypass -windowstyle hidden -noninteractive -nologo -NoProfile Get-ChildItem $env:temp\ProfileUnity ^| Where-Object {$_.LastWriteTime -lt (Get-Date).AddDays(-2)} ^| Remove-Item -Recurse -Force -ErrorAction SilentlyContinue
Solution 2:
Use Powershell as FileSpec
FileSpec: powershell.exe
Arguments: -executionpolicy bypass -windowstyle hidden -noninteractive -nologo -NoProfile Get-ChildItem $env:temp\ProfileUnity | Where-Object {$_.LastWriteTime -lt (Get-Date).AddDays(-2)} | Remove-Item -Recurse -Force -ErrorAction SilentlyContinue
Solution 3:
Files on a network share and using global variables
FileSpec: powershell.exe
Arguments: -executionpolicy bypass -windowstyle hidden -noninteractive -nologo -NoProfile Get-ChildItem {ProfileShare}\$env:USERNAME\Logs\ProfileUnity | Where-Object {$_.LastWriteTime -lt (Get-Date).AddDays(-2)} | Remove-Item -Recurse -Force -ErrorAction SilentlyContinue
- Use of GlobalVariable for UNC path
Solution 4:
Could be wrapped into a PS1
# Set the UNC share path where the log files are located
$sharePath = "\\server\share\logfiles"
# Set the number of days after which log files should be deleted
$days = 30
# Get the current date and time
$now = Get-Date
# Calculate the cutoff date for log files to be deleted
$cutoffDate = $now.AddDays(-$days)
# Get a list of log files in the share path that are older than the cutoff date
$logFiles = Get-ChildItem $sharePath -Recurse -File | Where-Object { $_.LastWriteTime -lt $cutoffDate }
# Delete the log files
foreach ($file in $logFiles) { Remove-Item $file.FullName }
Product: ProfileUnity-FlexApp
Product Version: 6.8.x