TFS Build: `Microsoft.TeamFoundation.PowerShell' is not installed on this computer
<p>When I'm logged in to tfs build server using local account and execute following powershell command:</p>

<pre><code>Add-PSSnapin Microsoft.TeamFoundation.PowerShell
</code></pre>

<p>it loads the tfs cmdlets correctly. However, when I trigger a build on tfs server that invokes the script, it fails with message:</p>

<blockquote>
  <p>'Microsoft.TeamFoundation.PowerShell' is not installed on this computer.</p>
</blockquote>

<p>The build agent runs under service account. What should I do?</p>

<p><strong>EDIT</strong>:
I had to edit the reqistry entry from the first link in @Alexis Coles' answer to make it work with version 2015 of TFS PowerTools:</p>

<pre><code>Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\PowerShellSnapIns\Microsoft.TeamFoundation.PowerShell]
"PowerShellVersion"="4.0"
"Vendor"="Microsoft Corporation"
"Description"="This is a PowerShell snap-in that includes the Team Foundation Server cmdlets."
"VendorIndirect"="Microsoft.TeamFoundation.PowerShell,Microsoft"
"DescriptionIndirect"="Microsoft.TeamFoundation.PowerShell,This is a PowerShell snap-in that includes the Team Foundation Server cmdlets."
"Version"="14.0.0.0"
"ApplicationBase"="C:\\Program Files (x86)\\Microsoft Team Foundation Server 2015 Power Tools"
"AssemblyName"="Microsoft.TeamFoundation.PowerTools.PowerShell, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
"ModuleName"="C:\\Program Files (x86)\\Microsoft Team Foundation Server 2015 Power Tools\\Microsoft.TeamFoundation.PowerTools.PowerShell.dll"
"CustomPSSnapInType"="Microsoft.TeamFoundation.PowerTools.PowerShell.TFPSSnapIn"

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\PowerShell\1\PowerShellSnapIns\Microsoft.TeamFoundation.PowerShell]
"PowerShellVersion"="4.0"
"Vendor"="Microsoft Corporation"
"Description"="This is a PowerShell snap-in that includes the Team Foundation Server cmdlets."
"VendorIndirect"="Microsoft.TeamFoundation.PowerShell,Microsoft"
"DescriptionIndirect"="Microsoft.TeamFoundation.PowerShell,This is a PowerShell snap-in that includes the Team Foundation Server cmdlets."
"Version"="14.0.0.0"
"ApplicationBase"="C:\\Program Files (x86)\\Microsoft Team Foundation Server 2015 Power Tools"
"AssemblyName"="Microsoft.TeamFoundation.PowerTools.PowerShell, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
"ModuleName"="C:\\Program Files (x86)\\Microsoft Team Foundation Server 2015 Power Tools\\Microsoft.TeamFoundation.PowerTools.PowerShell.dll"
"CustomPSSnapInType"="Microsoft.TeamFoundation.PowerTools.PowerShell.TFPSSnapIn"
</code></pre>

<p>Double check <code>AssemblyName</code>, <code>ApplicationBase</code>, <code>ModuleName</code> and <code>Version</code> entries. Script above works with <strong>Microsoft Team Foundation Server 2015 Power Tools</strong></p>