Created
September 7, 2021 09:23
-
-
Save michael-baker/da83c79d0b9fec22b8cf293a13fcb747 to your computer and use it in GitHub Desktop.
Query Build Visual Studio 2019 CSC Version on TFS 2018 Agents
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This script finds all build agents for TFS 2018 in the "default" pool and then executes CSC --version for Visual Studio 2019 | |
# against that agent. | |
# Get all pools | |
$pools = Invoke-RestMethod -UseDefaultCredentials -Method Get -Uri "https://tfs.com/tfs/_apis/distributedtask/pools" -UseBasicParsing | |
# Find the ID of the pool we want | |
$id = $pools.value | Where-Object { $_.name -eq "Default" } | Select-Object -ExpandProperty id -Unique | |
$agents = Invoke-RestMethod -UseDefaultCredentials -Method Get -Uri "https://tfs.com/tfs/_apis/distributedtask/pools/$id/agents?includeCapabilities=false&includeAssignedRequest=true" | |
$hosts = $agents.value | Select-Object -ExpandProperty name | % { $_.Split('_')[0] } # the naming pattern for this installation is <host>_<name> | |
foreach ($hostComputer in $hosts) { | |
Invoke-Command -ComputerName $hostComputer -ScriptBlock { | |
$InformationPreference = 'Continue' | |
function Start-Process($fileName, $argumentList) { | |
$psi = [System.Diagnostics.ProcessStartInfo]::new() | |
$psi.CreateNoWindow = $true | |
$psi.UseShellExecute = $false | |
$psi.RedirectStandardOutput = $true | |
$psi.RedirectStandardError = $true | |
$psi.FileName = $fileName | |
$psi.Arguments = $argumentList | |
$process = [System.Diagnostics.Process]::new() | |
# Adding event handers for stdout and stderr. | |
$scripBlock = { | |
if (![String]::IsNullOrEmpty($EventArgs.Data)) | |
{ | |
Write-Information $EventArgs.Data | |
} | |
} | |
$stdOutEvent = Register-ObjectEvent ` | |
-InputObject $process ` | |
-Action $scripBlock ` | |
-EventName 'OutputDataReceived' | |
$stdErrEvent = Register-ObjectEvent ` | |
-InputObject $process ` | |
-Action $scripBlock ` | |
-EventName 'ErrorDataReceived' | |
$process.StartInfo = $psi | |
try { | |
[void]$process.Start() | |
$process.BeginOutputReadLine() | |
$process.BeginErrorReadLine() | |
while (-not $process.WaitForExit(100)) { | |
# Allow interrupts like CTRL + C by doing a non-blocking wait | |
} | |
$process.WaitForExit() | |
} finally { | |
Unregister-Event -SourceIdentifier $stdOutEvent.Name | |
Unregister-Event -SourceIdentifier $stdErrEvent.Name | |
$process.Dispose() | |
} | |
} | |
$instance = Get-CimInstance MSFT_VSInstance -ComputerName $hostComputer | Where-Object { $_.Version -ge 16 } | Select-Object -First 1 | |
$csc = [System.IO.Path]::Combine($instance.InstallLocation, "MSBuild" ,"Current", "Bin", "Roslyn", "csc.exe") | |
Write-Information "$Env:ComputerName" | |
Start-Process -Filename $csc -ArgumentList @("-version") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment