Delete Temporary Internet Files from All Profiles in Windows 7 or Vista Using PowerShell


# Delete_Temp_Files_W7.ps1
# This script deletes all files in all users' Temp and Temporary Internet Files
# folders on a Windows Vista or Windows 7 machine. 



Deletes all files and subdirectories in %UserProfile%AppDataLocalTemp and
%UserProfile%AppDataLocalMicrosoftWindowsTemporary Internet Files for all user 
profiles on the machine.


No parameters are accepted by this script.




The script will not remove any files that are in use by other processes, and will 
throw an error upon encountering any in use files.


# Create array containing all user profile folders
$colProfiles = Get-ChildItem "C:Users" -Name
# Remove the All Users profile from the array
$colProfiles = $colProfiles -ne "Public"

# Removes temporary files from each user profile folder
ForEach ( $objProfile in $colProfiles ) {
    # Remove all files and folders in user's Temp folder
    Get-ChildItem "C:Users$objProfileAppDataLocalTemp*" -recurse | remove-item -force -recurse
    # Remove all files and folders in user's Temporary Internet Files. The -force switch on Get-ChildItem gets hidden directories as well.
    Get-ChildItem "C:Users$objProfileAppDataLocalMicrosoftWindowsTemporary Internet Files*" -recurse -force | remove-item -force -recurse

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s