Accessing the build revision number in Powershell script during TFS build Accessing the build revision number in Powershell script during TFS build powershell powershell

Accessing the build revision number in Powershell script during TFS build


Use the build variables.

From PowerShell use $Env:BUILD_BUILDNUMBER if you’re using TFS 2015.

See MSDN: Use a PowerShell script to customize your build process

For previous versions: Team Foundation Build environment variables


you can use following powershell script to parse Build number

[String]$myrev = $Env:BUILD_BUILDNUMBER$result = $myrev.Substring($myrev.LastIndexOf('.') + 1)Write-Host $result