-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathGet-AzDoEnvironment.ps1
More file actions
98 lines (84 loc) · 2.91 KB
/
Get-AzDoEnvironment.ps1
File metadata and controls
98 lines (84 loc) · 2.91 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
function Get-AzDoEnvironment {
<#
.SYNOPSIS
Creates a Build Validation policy on a branch
.DESCRIPTION
Creates a Build Validation policy on a branch
.EXAMPLE
$Params = @{
CollectionUri = "https://dev.azure.com/contoso"
ProjectName = "Project 1"
}
Get-AzDoEnvironment @Params
This example retrieves all environments in the specified project ("Project 1") in Azure DevOps.
.EXAMPLE
$Params = @{
CollectionUri = "https://dev.azure.com/contoso"
ProjectName = "Project 1"
EnvironmentName = "Environment 1"
}
Get-AzDoEnvironment @Params
This example retrieves details of the environment named "Environment 1" in the specified project ("Project 1") in Azure DevOps.
.EXAMPLE
$Params = @{
CollectionUri = "https://dev.azure.com/contoso"
ProjectName = "Project 1"
EnvironmentName = @("Environment 1", "Environment 2")
}
Get-AzDoEnvironment @Params
This example retrieves details of multiple environments ("Environment 1" and "Environment 2") in the specified project ("Project 1") in Azure DevOps.
.OUTPUTS
[PSCustomObject]@{
CollectionUri = $CollectionUri
ProjectName = $ProjectName
RepoName = $RepoName
Id = $result.id
Url = $result.url
}
.NOTES
#>
[CmdletBinding(SupportsShouldProcess)]
param (
# Collection Uri of the organization
[Parameter(Mandatory, ValueFromPipelineByPropertyName, ValueFromPipeline)]
[ValidateScript({ Validate-CollectionUri -CollectionUri $_ })]
[string]
$CollectionUri,
# Project where the pipeline will be created.
[Parameter(Mandatory, ValueFromPipelineByPropertyName, ValueFromPipeline)]
[string]
$ProjectName,
# Name of the Build Validation policy. Default is the name of the Build Definition
[Parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)]
[string[]]
$EnvironmentName
)
begin {
$result = @()
Write-Verbose "Starting function: Get-AzDoEnvironment"
}
process {
$params = @{
uri = "$CollectionUri/$ProjectName/_apis/pipelines/environments"
version = "7.2-preview.1"
Method = "GET"
}
if ($PSCmdlet.ShouldProcess($CollectionUri, "Get Environments from: $($PSStyle.Bold)$ProjectName$($PSStyle.Reset)")) {
$result += (Invoke-AzDoRestMethod @params).value | Where-Object { -not $EnvironmentName -or $_.Name -in $EnvironmentName }
} else {
Write-Verbose "Calling Invoke-AzDoRestMethod with $($params| ConvertTo-Json -Depth 10)"
}
}
end {
if ($result) {
$result | ForEach-Object {
[PSCustomObject]@{
CollectionUri = $CollectionUri
ProjectName = $ProjectName
EnvironmentId = $_.id
EnvironmentName = $_.name
}
}
}
}
}