From ce824e74e7c2d2fa17d62afc543f01a989c40a1e Mon Sep 17 00:00:00 2001 From: dyoder Date: Mon, 24 May 2021 15:33:14 -0400 Subject: [PATCH] removed unnecessary variable --- Cleanup-SystemTempFiles.ps1 | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/Cleanup-SystemTempFiles.ps1 b/Cleanup-SystemTempFiles.ps1 index 99d77b9..e8882df 100644 --- a/Cleanup-SystemTempFiles.ps1 +++ b/Cleanup-SystemTempFiles.ps1 @@ -1,7 +1,4 @@ -## Path to the system temp folder -$SysTemp = "${Env:SystemRoot}\TEMP" - -## When deleting temp files en masse, only delete files/folders older than the number of days specified here +## When deleting temp files en masse, only delete files/folders older than the number of days specified here $OlderThan = 7 $TimeDelta = New-TimeSpan -Days $OlderThan @@ -11,18 +8,18 @@ If ( IsAdmin ) LogMsg "Running with administrative privileges" ## Remove all *.evtx files from $SysTemp - $EventLogs = Get-ChildItem -Path "${SysTemp}\*" -File -Filter *.evtx + $EventLogs = Get-ChildItem -Path "${Env:SystemRoot}\TEMP\*" -File -Filter *.evtx If ( $EventLogs ) { - LogMsg "Deleting all event logs from ${SysTemp}" + LogMsg "Deleting all event logs from ${Env:SystemRoot}\TEMP" ForEach ( $EventLog in $EventLogs ) { Remove-Item $EventLog -Force -ErrorAction SilentlyContinue } } ## Remove misc logs and error reports - $MiscLogs = Get-ChildItem -Path "${SysTemp}\*" -File -Include "${Env:COMPUTERNAME}-*.log", "AppxErrorReport_*.txt" + $MiscLogs = Get-ChildItem -Path "${Env:SystemRoot}\TEMP\*" -File -Include "${Env:COMPUTERNAME}-*.log", "AppxErrorReport_*.txt" If ( $MiscLogs ) { - LogMsg "Deleting misc logs from ${SysTemp}" + LogMsg "Deleting misc logs from ${Env:SystemRoot}\TEMP" ForEach ( $MiscLog in $MiscLogs ) { Remove-Item $MiscLog -Force -ErrorAction SilentlyContinue } } @@ -36,10 +33,10 @@ If ( IsAdmin ) } ## Remove all system temp files older than 7 days - $OldTempFiles = Get-ChildItem -Path $SysTemp | Where { $_.LastWriteTime -lt ((Get-Date) - $TimeDelta) } + $OldTempFiles = Get-ChildItem -Path "${Env:SystemRoot}\TEMP" | Where { $_.LastWriteTime -lt ((Get-Date) - $TimeDelta) } If ( $OldTempFiles ) { - LogMsg "Deleting all temp files not modified in ${OlderThan} day(s) from ${SysTemp}" + LogMsg "Deleting all temp files not modified in ${OlderThan} day(s) from ${Env:SystemRoot}\TEMP" ForEach ( $OldTempFile in $OldTempFiles ) { Remove-Item $OldTempFile -Force -Recurse -ErrorAction SilentlyContinue } }