This function will do a cleanup for the local temp folder.

With two options with or without closing programs that often uses the temp folder.

Syntax:
Clean-Temp option

Example:
Clean-Temp close
Clean-Temp

Help:
Get-Help Clean-Temp -detailed

Updated: 12/26/2009
1. Some tweaks to the code
2. Help text for PowerShell 2.0

PowerShell
Edit|Remove
function Clean-Temp {
<#
	.Synopsis
		Will clean the local temp folder
	.Description
		Will clean the local temp folder
	.Parameter Close
	    Closes running programs
	.Example
		Clean-Temp
	.Example
		Clean-Temp Close
	.Notes
	 NAME:      Clean-Temp
	 AUTHOR:    Fredrik Wall, fredrik@poweradmin.se
	 BLOG:		poweradmin.se/blog
	 LASTEDIT:  04/07/2010
#>
	param($extra)
	if ($extra -eq 'close') {
		# Some programs that often uses temp dir for temp files
		process iexplore* | kill
		process outlook* | kill
		process word* | kill
		process excel* | kill
		process msn* | kill
		process chrome* | kill
		process tweetdeck* | kill
	}
		
		$myTemp = "$Env:temp"
		Get-Childitem $myTemp | Remove-Item -Recurse -Force -ErrorAction SilentlyContinue
		$myTemp = $null

}