Functions/Public/Get-GocdResourceUsage.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
function Get-GocdResourceUsage {
    [CmdletBinding()]
    param(
        [Parameter()]
        [ValidateNotNullOrEmpty()]
        [string]
        $Pipeline = '*'
    )

    $Pipelines = Get-GocdPipeline | Where-Object { $_.Name -like $Pipeline } | Select-Object -ExpandProperty Name
    foreach ($PipelineName in $Pipelines) {
        $PipelineConfiguration = Get-GocdPipelineConfiguration -Pipeline $PipelineName
        
        foreach ($Stage in $PipelineConfiguration.stages) {
            foreach ($Job in $Stage.jobs) {
                foreach ($Resource in $Job.resources) {
                    [pscustomobject]@{
                        Pipeline = $PipelineName
                        Stage    = $Stage.Name
                        Job      = $Job.Name
                        Resource = $Resource
                    }
                }
            }
        }
    }
}