Skip to content

Instantly share code, notes, and snippets.

@ukcoderj
Created September 1, 2017 10:31
Show Gist options
  • Save ukcoderj/38f37fd23000aeb630f97da22138c986 to your computer and use it in GitHub Desktop.
Save ukcoderj/38f37fd23000aeb630f97da22138c986 to your computer and use it in GitHub Desktop.
Powershell Check Out / In Document from VSTS (TFS)
Add-PSSnapin Microsoft.TeamFoundation.PowerShell
# This file requires the TFS Power Tools (2015+). When installing, you must select Custom Installation and select PowerShell Cmdlets
# *VSTS Login*
# YOU MUST go to 'Options' and turn on 'Allow scripts to access OAuth token' for the buld
$url = "$($env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI)$env:SYSTEM_TEAMPROJECTID/_apis/build/definitions/$($env:SYSTEM_DEFINITIONID)?api-version=2.0"
Write-Host "URL: $url"
$definition = Invoke-RestMethod -Uri $url -Headers @{
Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN"
}
Write-Host "Definition = $($definition | ConvertTo-Json -Depth 100)"
"***************** Authenticated *****************"
" *VSTS Check Out file* from $fileToUpdate"
Add-TfsPendingChange -Edit -Item $fileToUpdate -Verbose -ErrorAction Stop -wa 0
# read the file, update the number and save it back
$stuff = Get-Content $fileToUpdate
# modify stuff - make sure you actually make a change!
Set-Content -Value $stuff -Path $fileToUpdate
# *VSTS Check In* Check in the file after changes.
" *VSTS Check In"
New-TfsChangeset -Item $fileToUpdate -Verbose -Comment "***NO_CI***" -Override true -ErrorAction Stop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment