Have you ever had a user call in and say that they have run out of disk space? We tend to see that when computers are deployed with small hard drives. Here is a function that you may find handy to use for these issues. You can run it as a job by removing the comment #-Jobs. Remove Comment for Get-Job to get the job status.

   Remove-TempFiles v1.0
   By Michael J. Thomas
   Created 06/03/2019
   Updated 06/03/2019
   Removes the Temp Files on local and remote computers. It also disables hibernation to save space. 
   C:\temp\, c:\windows\temp\, c:\windows\prefetch\, and all Users Appdata\local\Temp\ files. 
   Remove the Temp files on the local computer.
    Remove the Temp files on a remote computer.
    Remove-TempFiles -ComputerName "Computer01"
    Remove the Temp files on remote computers.
    Remove-TempFiles -UserName "Computer01","Computer02"

Function Remove-TempFiles{
[string[]]$ComputerName = $env:COMPUTERNAME

Foreach ($Computer in $ComputerName){
Invoke-Command -ComputerName $ComputerName -ScriptBlock{
powercfg /hibernate off
Start-Sleep 2
Remove-Item "C:\Windows\ccmcache\*", "C:\temp\*","c:\windows\temp\*",“C:\Windows\Prefetch\*”,“C:\Users\*\Appdata\Local\Temp\*” -Force -Recurse -Verbose
} #-AsJob -JobName "CleanMgrJob"
#Get-Job -Name "CleanMgrJob"


Popular posts from this blog


Keep All Network Connections Private ( Set-PrivateNetwork )