Skip to content

Instantly share code, notes, and snippets.

@Tiberriver256
Last active October 16, 2021 21:44
Show Gist options
  • Save Tiberriver256/afbc749e1ccc04b287fae296694fea1c to your computer and use it in GitHub Desktop.
Save Tiberriver256/afbc749e1ccc04b287fae296694fea1c to your computer and use it in GitHub Desktop.
Used to generate a report of Azure DevOps agent specifications to determine which classic build/release definitions are using different operating systems
Import-Module VSTeam
function Get-AzureDevOpsAgentSpecifications {
[CmdletBinding()]
param(
[Parameter(Mandatory)]
[string]
$Account,
[Parameter(Mandatory)]
[securestring]
$PAT
)
Set-VSTeamAccount -Account $Account -SecurePersonalAccessToken $PAT
Write-Verbose "Fetching Projects from your account: [$Account]"
$Projects = Get-VSTeamProject
Write-Verbose "Found [$($Projects.Count)] Projects to check"
$Report = @()
foreach ($Project in $Projects) {
$ClassicBuildType = "1"
Write-Verbose "Fetching all classic pipelines from the project: [$($Project.Name)]"
$ClassicBuilds = Get-VSTeamBuildDefinition -ProjectName $Project.Name |
Where-Object { $_.InternalObject.process.type -eq $ClassicBuildType }
Write-Verbose "Adding [$($ClassicBuilds.Count)] classic build pipelines to the report"
foreach ($Build in $ClassicBuilds) {
$Report += [pscustomobject]@{
Organization = $Account
Project = $Project.Name
Name = $Build.Name
Type = "Build"
ReleaseStage = "N/A"
Phase = "N/A"
WebLink = $Build.InternalObject._links.web.href
AgentSpecification = $Build.InternalObject.process.target.agentSpecification.identifier
}
$BuildPhasesWithUniqueAgent = $Build.InternalObject.process.phases | where { $Null -ne $_.target.agentSpecification }
foreach ($BuildPhase in $BuildPhasesWithUniqueAgent) {
$Report += [pscustomobject]@{
Organization = $Account
Project = $Project.Name
Name = $Build.Name
Type = "Build"
ReleaseStage = "N/A"
Phase = $BuildPhase.name
WebLink = $Build.InternalObject._links.web
AgentSpecification = $Build.InternalObject.process.target.agentSpecification.identifier
}
}
}
Write-Verbose "Fetching all classic release pipelines from the project: [$($Project.Name)]"
$ReleasePipelines = Get-VSTeamReleaseDefinition -ProjectName $Project.Name | foreach { Get-VSTeamReleaseDefinition -ProjectName $Project.Name -Id $_.Id }
Write-Verbose "Adding [$($ReleasePipelines.Count)] classic release pipelines to the report"
foreach ($Release in $ReleasePipelines) {
foreach ($ReleaseStage in $Release.InternalObject.environments) {
foreach ($ReleaseStagePhase in $ReleaseStage.deployPhases) {
$Report += [pscustomobject]@{
Organization = $Account
Project = $Project.Name
Name = $Release.Name
Type = "Release"
ReleaseStage = "N/A"
Phase = $ReleaseStage.name
WebLink = $Release.Links.Web
AgentSpecification = $ReleaseStagePhase.deploymentInput.agentSpecification.identifier
}
}
}
}
}
$Report
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment