Public/New-bConnectEndpoint.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
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
Function New-bConnectEndpoint() {
    <#
        .Synopsis
            Create a new endpoint.
        .Parameter Type
            enum bConnectEndpointType.
        .Parameter DisplayName
            DisplayName of the new endpoint. This is also used as hostname for Windows-Endpoints.
        .Parameter GroupGuid
            Valid GUID of the target OU (default: "Logical Group").
        .Parameter PrimaryUser
            Primary user of this endpoint. Mandatory for WindowsPhone-Endpoints.
        .Outputs
            NewEndpoint (see bConnect documentation for more details).
    #>


    [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'low')]
    [OutputType("System.Management.Automations.PSObject","System.Boolean")]
    Param (
        [Parameter(Mandatory=$true)][bConnectEndpointType]$Type,
        [Parameter(Mandatory=$true)][string]$DisplayName,
        [string]$GroupGuid = "C1A25EC3-4207-4538-B372-8D250C5D7908", #guid of "Logical Group" as fallback
        [string]$PrimaryMac,
        [string]$HostName,
        [string]$Domain,
        [string]$Options,
        [string]$GuidBootEnvironment,
        [string]$GuidHardwareProfile,
        [string]$PrimaryUser = "",
        [ValidateSet("LAN","Internet","Dynamic")][string]$Mode,
        [switch]$ExtendedInternetMode
    )

    $_connectVersion = Get-bConnectVersion
    If($_connectVersion -ge "1.0") {
        $_body = @{
            Type = $type;
            DisplayName = $displayname;
            GuidGroup = $groupGuid;
            PrimaryUser = $primaryUser
        }

        If($Type -eq [bConnectEndpointType]::WindowsEndpoint) {
            If(![string]::IsNullOrEmpty($PrimaryMac)) {
                $_body += @{ PrimaryMac = $PrimaryMac }
            }

            If(![string]::IsNullOrEmpty($HostName)) {
                $_body += @{ HostName = $HostName }
            }

            If(![string]::IsNullOrEmpty($Domain)) {
                $_body += @{ Domain = $Domain }
            }

            If(![string]::IsNullOrEmpty($Options)) {
                $_body += @{ Options = $Options }
            }

            If(![string]::IsNullOrEmpty($GuidBootEnvironment)) {
                $_body += @{ GuidBootEnvironment = $GuidBootEnvironment }
            }

            If(![string]::IsNullOrEmpty($GuidHardwareProfile)) {
                $_body += @{ GuidHardwareProfile = $GuidHardwareProfile }
            }

            If($Mode) {
                $_body += @{ Mode = $Mode }
            }

            If($ExtendedInternetMode) {
                $_body += @{ ExtendedInternetMode = $ExtendedInternetMode }
            }
        }

        if($PSCmdlet.ShouldProcess($_body.DisplayName, "Create new endpoint.")){
            return Invoke-bConnectPost -Controller "Endpoints" -Version $_connectVersion -Data $_body
        } else {
            return $false
        }
    } else {
        return $false
    }
}