AzureDevOps.VariableGroups/Public/New-AzureDevOpsVariableGroup.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
function New-AzureDevOpsVariableGroup
{
    <#
    .SYNOPSIS
    Create a new variable group object
 
    .DESCRIPTION
    Creates a new variable group object.
 
    .PARAMETER Name
    The name of the new variable group.
 
    .PARAMETER Description
    The description of the variable group.
 
    .PARAMETER Variables
    The variables contained in the variable group.
 
    .EXAMPLE
    $Variables = @();
    $Variables += New-AzureDevOpsVariable -Name "MyVariable" -Value "MyVariableValue";
    $Variables += New-AzureDevOpsVariable -Name "MySecretVariable" -Value "MySecretVariableValue" -Secret;
    $myGroup = New-AzureDevOpsVariableGroup -Name "MyVariableGroup" -Value "MyValue" -Variables $Variables
    #>


    param
    (
        [string]$Name,
        [string]$Description,
        [PSCustomObject[]]$Variables
    )

    $group = [PSCustomObject]@{
        name = $Name
        description = $Description
        variables = [PSCustomObject]@{}
        type = "Vsts"
    }

    foreach($variable in $Variables) {
        Add-Member -InputObject $group.variables -MemberType NoteProperty -Name $variable.Name -Value $variable.Value;
    }

    return $group;
}