title: Large TFSUser\AppData\Local\Temp Directory on Build Machine
body: <p>I'm using TFS 2012 Update 1 on Windows Server 2008 R2.  We have the TFS build running under the account TFSUser.  The other day we ran out of space on our build machine.  Upon investigation I found that the folder C:\Users\TFSUser\AppData\Local\Temp had over 50GB of files in it, some dating back as far as October of 2012.  None of the files are overly large, but they don't ever seem to get cleaned up.</p>
  
  <p>Investigating today shows that folder gets written to a lot during an automated build.  Why aren't these files getting cleaned up and what can I do to ensure my build machine doesn't run out of space again due to this issue?</p>
  
  <p><strong>Update 2013-03-13</strong><br/>
  I created a small powershell script that runs nightly to delete the temp directory contents.  Here's the powershell script:</p>
  
  <pre><code>Stop-Service TFSBuildServiceHost.2012
  Remove-Item Drive:\Path\To\TFSUser\AppData\Local\Temp\* -recurse -exclude Build*
  Start-Service TFSBuildServiceHost.2012
  </code></pre>
  
  <p>I have the task run with elevated privileges nightly as the TFSUser account.  The elevated privileges are needed because we need to start and stop services.</p>