# TFS Scripts

I’m definitely not a TFS genius, but I’ve written a few scripts that have proven helpful in dealing with some of the issues that come up with version control.
First, here’s a simple one. This just automates a simple TF.EXE command to show the last 50 check-ins in our project. This particular command opens a GUI window to show the output.

```/andyhuey/54710641 2 3 4 5 [string]\$tf = "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\TF.exe" pushd cd c:\ax2012tfs & \$tf history /r /stopafter:50 * popd```

Second, here’s one to show the TFS status. This command, unlike the previous, sends output to the console, so I’m piping it to Notepad++, so I can see it there.

```/andyhuey/54710721 2 3 4 5 6 7 8 9 [string]\$tf = "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\TF.exe" [string]\$npp = "C:\Program Files (x86)\Notepad++\notepad++.exe" # [string]\$tempFile = [System.IO.Path]::GetTempFileName() [string]\$tempFile = "\$env:temp\tfStatus.txt" pushd cd c:\ax2012tfs & \$tf status > \$tempFile popd & \$npp \$tempFile```

And third, here’s a somewhat more complicated one. This one allows you to diff two changesets, and pipes the output to Notepad++. But, if there’s an error, it instead shows a “press any key” message, so you can see the error in the console window. Notepad++ has syntax highlighting for diff files, so the output is reasonably nice-looking.

```/andyhuey/54710841 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 param ( [string]\$cs1 = \$( Read-Host "Enter changeset 1 (as c9999)" ), [string]\$cs2 = \$( Read-Host "Enter changeset 2 (as c9999)" ) ) [string]\$tf = "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\TF.exe" [string]\$npp = "C:\Program Files (x86)\Notepad++\notepad++.exe" [string]\$tempFile = "\$env:temp\tfDiff.diff" pushd cd c:\ax2012tfs & \$tf diff cus /v:\$cs1~\$cs2 /r /f:unified > \$tempFile if (\$LastExitCode -eq 0) { & \$npp \$tempFile } else { Write-Host "Press any key to continue ..." \$x = \$host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") } popd```

This pretty much concludes the overview of my utility scripts that I started a few days ago. I hope it was helpful to someone. If not, at least I’ve got them documented now, so if I lose them again, I know where to look!