Public/Set-bConnectVariable.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
46
47
48
49
50
Function Set-bConnectVariable() {
    <#
        .Synopsis
            Set variable for a object.
        .Parameter ObjectGuid
            Valid GUID of an object.
        .Parameter Scope
            enum bConnectVariableScope.
        .Parameter Category
            Valid variable category.
        .Parameter Name
            Valid variable name.
        .Parameter Value
            New value.
        .Outputs
            Bool
    #>


    Param (
        [Parameter(Mandatory=$true)][string]$ObjectGuid,
        [Parameter(Mandatory=$true)][bConnectVariableScope]$Scope,
        [Parameter(Mandatory=$true)][string]$Category,
        [Parameter(Mandatory=$true)][string]$Name,
        [Parameter(Mandatory=$true)][string]$Value,
        [switch]$UseDefault
    )

    $_connectVersion = Get-bConnectVersion
    If($_connectVersion -ge "1.0") {
        $_variable = @{
            Category = $Category;
            Name = $Name;
            UseDefault = $UseDefault.ToString();
            Value = $Value
        }

        $_variables = @($_variable)

        $_body = @{
            ObjectId = $ObjectGuid;
            Scope = $Scope.ToString();
            Variables = $_variables
        }

        return Invoke-bConnectPut -Controller "Variables" -Version $_connectVersion -Data $_body
    } else {
        return $false
    }
}