Thursday, October 1, 2015

Windows / Sharepoint / User Temp files Auto deletion PowerShell Script

Windows / Sharepoint / User Temp files Auto deletion PowerShell Script

+++++++++++++++++++++++++++++++++++++++++
$tempfolders = @("C:\Windows\Temp\*", "C:\Users\*\Appdata\Local\Temp\*", "C:\Windows\ServiceProfiles\LocalService\AppData\Local\Temp\*", "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\PETGeneral\DMSTemp\*" ,"C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\PETV2\DMSTemp\*")

Remove-Item $tempfolders -force -recurse

+++++++++++++++++++++++++++++++++++++++++

Copy above text in PS1 file. e.g. TempFileDeletion.ps1

Schedule it with Windows Task Scheduler :



Run the below command in PowerShell for changing Execution Policy.



Its Done.

Solved : The user profile failed to attach. The process cannot access the file becase it is being used by another process

Issue :  The user profile failed to attach. Please contact Support. Status : 0x0000000B, Message: Cannot open virtual disk Error Code: 0x000...