fix several places where full path was not provided to Remove-Item
This commit is contained in:
@@ -55,7 +55,7 @@ If ( $CBSLogs ) {
|
||||
$OldTempFiles = Get-ChildItem -Path "${Env:SystemRoot}\TEMP" | Where-Object { $_.LastWriteTime -lt ((Get-Date) - $TimeDelta) }
|
||||
If ( $OldTempFiles ) {
|
||||
Write-Output "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 }
|
||||
ForEach ( $OldTempFile in $OldTempFiles ) { Remove-Item $OldTempFile.FullName -Force -Recurse -ErrorAction SilentlyContinue }
|
||||
}
|
||||
|
||||
# Remove all old files from the Recycle Bin
|
||||
@@ -87,7 +87,7 @@ If ( Test-Path "${Env:SystemDrive}\hiberfil.sys" ) {
|
||||
$PDCRevocationDumpFiles = Get-ChildItem -Path "${Env:SystemRoot}\LiveKernelReports\*" -File -Include "PDCRevocation-*.dmp"
|
||||
If ( $PDCRevocationDumpFiles ) {
|
||||
Write-Output "Deleting PDCRevocation dump files from ${Env:SystemRoot}\LiveKernelReports"
|
||||
ForEach ( $PDCRevocationDump in $PDCRevocationDumpFiles ) { Remove-Item $PDCRevocationDump -Force -ErrorAction SilentlyContinue }
|
||||
ForEach ( $PDCRevocationDump in $PDCRevocationDumpFiles ) { Remove-Item $PDCRevocationDump.FullName -Force -ErrorAction SilentlyContinue }
|
||||
}
|
||||
|
||||
# Remove Genetec application crash dumps
|
||||
@@ -128,7 +128,7 @@ If ( Test-Path $ADSKInst ) {
|
||||
ForEach ( $f in $foldersToDelete ) {
|
||||
$path = $f.FullName
|
||||
Write-Output "Deleting Autodesk installer directory: ""${path}"""
|
||||
Try { Remove-Item $f -Force -Recurse -ErrorAction SilentlyContinue }
|
||||
Try { Remove-Item $f.FullName -Force -Recurse -ErrorAction SilentlyContinue }
|
||||
Catch { Write-Error $_.Exception.Message }
|
||||
}
|
||||
}
|
||||
@@ -151,7 +151,7 @@ $ChocolateyTempDirs = Get-ChildItem -Path $ChocolateyCache -Directory -ErrorActi
|
||||
If ( $ChocolateyTempDirs ) {
|
||||
Write-Output "Deleting all temp directories not modified in ${OlderThan} day(s) from ""${ChocolateyCache}"""
|
||||
ForEach ( $d in $ChocolateyTempDirs ) {
|
||||
Try { Remove-Item $d -Force -Recurse -ErrorAction SilentlyContinue }
|
||||
Try { Remove-Item $d.FullName -Force -Recurse -ErrorAction SilentlyContinue }
|
||||
Catch { Write-Error $_.Exception.Message }
|
||||
}
|
||||
}
|
||||
@@ -163,7 +163,7 @@ ForEach ( $userProfile in $(Get-UserProfiles) ) {
|
||||
$OldTempFiles = Get-ChildItem -Path "${userProfile}\AppData\Local\Temp" -ErrorAction SilentlyContinue | Where-Object { $_.LastWriteTime -lt ((Get-Date) - $TimeDelta) }
|
||||
If ( $OldTempFiles ) {
|
||||
Write-Output "Deleting all temp files not modified in ${OlderThan} day(s) from ""${userProfile}\AppData\Local\Temp"""
|
||||
ForEach ( $OldTempFile in $OldTempFiles ) { Remove-Item $OldTempFile -Force -Recurse -ErrorAction SilentlyContinue }
|
||||
ForEach ( $OldTempFile in $OldTempFiles ) { Remove-Item $OldTempFile.FullName -Force -Recurse -ErrorAction SilentlyContinue }
|
||||
}
|
||||
|
||||
# Remove AutoCAD temp files
|
||||
@@ -172,7 +172,7 @@ ForEach ( $userProfile in $(Get-UserProfiles) ) {
|
||||
If ( $AutoCADTempFiles ) {
|
||||
Write-Output "Deleting AutoCAD temp files"
|
||||
ForEach ( $tempfile in $AutoCADTempFiles ) {
|
||||
Try { Remove-Item $tempfile -Force -ErrorAction SilentlyContinue }
|
||||
Try { Remove-Item $tempfile.FullName -Force -ErrorAction SilentlyContinue }
|
||||
Catch { Write-Error $_.Exception.Message }
|
||||
}
|
||||
}
|
||||
@@ -229,7 +229,7 @@ ForEach ( $userProfile in $(Get-UserProfiles) ) {
|
||||
ForEach ( $oldDownloadedApp in $OldDownloadedApps ) {
|
||||
$path = $oldDownloadedApp.FullName
|
||||
Write-Output " - Deleting: ""${path}"""
|
||||
Try { Remove-Item -Path $path -Force -ErrorAction SilentlyContinue }
|
||||
Try { Remove-Item -Path $path.FullName -Force -ErrorAction SilentlyContinue }
|
||||
Catch { Write-Error $_.Exception.Message }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user