function Start-TeamCityAgent { <# .SYNOPSIS Start the TeamCity Agent service(s) on a given host or on the host(s) in a given Agent Pool .PARAMETER ComputerName FQDN hostname of the TeamCity agent host where you want to start the Agent service .PARAMETER AgentPool TeamCity Agent Pool name of the TeamCity agents you want to start .LINK Get-TeamCityAgentHostnames .LINK Stop-TeamCityAgent .LINK https://ci.corp.alkamitech.com/agents.html?tab=agentPools .LINK https://ci.corp.alkamitech.com/app/rest/agentPools #> [CmdletBinding()] [OutputType([System.Void])] param( [Parameter(Mandatory = $true, ParameterSetName = "ComputerName")] $ComputerName, [Parameter(Mandatory = $true, ParameterSetName = "AgentPool")] $AgentPool ) # Why would you name the Keys like that, Tom? # # Because that's what they're named in TeamCity. Ideally, we'd be able to pull from the API # For a lot of things eventually and I don't want to make names up. # If you don't know the name, look it up in TeamCity. That's the name. # Also... # There are other pools that we don't touch the hosts of. "All" isn't really "All" $agentPoolToServiceNameFragments = @{ "Sandbox" = @('buildSandbox', 'migrateSandbox') "Dev/QA" = @('migrateQaDev', 'buildQaDev') "Production/Staging" = @('buildagent', 'migrateagent') "All" = @('buildSandbox', 'migrateSandbox', 'migrateQaDev', 'buildQaDev', 'buildagent', 'migrateagent') } # I hate everything about this except the last entry # I really want to be getting these from the REST API. Or something. ANYthing else. $agentPoolToAgentHostname = @{ "Sandbox" = @("tea316229.fh.local", "tea37021.fh.local") "Dev/QA" = @("tea316208.fh.local", "tea370104.fh.local") "Production/Staging" = @("tea316155.fh.local", "tea31697.fh.local") "All" = Get-TeamCityAgentHostnames } if ($PSCmdlet.ParameterSetName -eq "AgentPool") { $ComputerName = $agentPoolToAgentHostname[$AgentPool] } if ($PSCmdlet.ParameterSetName -eq "ComputerName") { $AgentPool = "All" } $agentServiceFragmentNames = $agentPoolToServiceNameFragments[$AgentPool] $sbStartAgent = { param($sbServiceNameFragments) $serviceNames = @() foreach ($serviceName in $sbServiceNameFragments) { $temp = (Get-ServiceInfoByCIMFragment $serviceName).name if ($null -ne $temp) { $serviceNames += $temp } } Start-Service $serviceNames } Invoke-ParallelServers -Servers $ComputerName -Script $sbStartAgent -Arguments ($agentServiceFragmentNames) }