Remove-TempFiles

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.



 <#
.Synopsis
   Remove-TempFiles v1.0
   By Michael J. Thomas
   Created 06/03/2019
   Updated 06/03/2019
    
.DESCRIPTION
   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. 
.EXAMPLE
   Remove the Temp files on the local computer.
   Remove-TempFiles
.EXAMPLE
    Remove the Temp files on a remote computer.
    Remove-TempFiles -ComputerName "Computer01"
.EXAMPLE
    Remove the Temp files on remote computers.
    Remove-TempFiles -UserName "Computer01","Computer02"
#>

Function Remove-TempFiles{
Param(
[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"
}
}

Comments

  1. Typically, any online on line casino or sports guide that accepts Malaysian gamers may also allow those gamers to run their accounts using ringgits. These gambling sites are additionally likely to to|prone to} be concentrating on Asian markets. International sites such as Bet365 are less likely to to|prone to} allow ringgits as a foreign money. Malaysian gamers usually run their accounts in US dollars if ringgits usually are not available. Given its popularity, soccer is the most popular sport amongst avid gamers. The CMD368 sportsbook features games 우리카지노 like as tennis, snooker, basketball, the Olympic Games, and volleyball.

    ReplyDelete

Post a Comment

Popular posts from this blog

Add-RemoteDesktopUsers

Invoke-Reprofile

Mike's Profile Cleanup Tool