Public/New-bConnectVariableDefinition.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
Function New-bConnectVariableDefinition() {
    <#
        .Synopsis
            New VariableDefinition.
        .Parameter Scope
            enum bConnectVariableScope.
        .Parameter Category
            Valid variable category.
        .Parameter Name
            Valid variable name.
        .Parameter Type
            enum bConnectVariableType.
        .Outputs
            New VariableDefinition (see bConnect documentation for more details).
    #>


    [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'low')]
    [OutputType("System.Management.Automations.PSObject","System.Boolean")]
    Param (
        [Parameter(Mandatory=$true)][bConnectVariableScope]$Scope,
        [Parameter(Mandatory=$true)][string]$Category,
        [Parameter(Mandatory=$true)][string]$Name,
        [Parameter(Mandatory=$true)][bConnectVariableType]$Type
    )

    $_connectVersion = Get-bConnectVersion
    If($_connectVersion -ge "1.0") {
        $_body = @{
            Scope = $Scope.ToString();
            Category = $Category;
            Name = $Name;
            Type = [string]$Type
        }

        if($PSCmdlet.ShouldProcess($_body.Name, "Create new variable definition.")){
            return Invoke-bConnectPost -Controller "VariableDefinitions" -Version $_connectVersion -Data $_body
        } else {
            return $false
        }
    } else {
        return $false
    }
}