Public/New-bConnectEndpointEnrollment.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
Function New-bConnectEndpointEnrollment() {
    <#
        .Synopsis
            Set an endpoint into enrollment mode.
        .Parameter EndpointId
            Valid GUID of an existing Windows endpoint.
        .Parameter EmailRecipient
            Valid Email address to send the enrollment information to.
        .Parameter Sync
            If set, the enrollment controller waits for the mail to be transfered to the SMTP server.
        .Outputs
            EnrollmentData (see bConnect documentation for more details).
    #>


    [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'medium')]
    [OutputType("System.Management.Automations.PSObject","System.Boolean")]
    Param (
        [Parameter(Mandatory=$true)][string]$EndpointId,
        [string]$EmailRecipient,
        [switch]$Sync
    )

    $_connectVersion = Get-bConnectVersion
    If($_connectVersion -ge "1.0") {
        $_body = @{
            EndpointId = $EndpointId;
        }

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

        If($Sync) {
            $_body += @{ Sync = $true }
        }

        if($PSCmdlet.ShouldProcess($_body.EndpointId, "Set endpoint to enrollment mode.")){
            return Invoke-bConnectPost -Controller "EndpointEnrollment" -Version $_connectVersion -Data $_body
        } else {
            return $false
        }
    } else {
        return $false
    }
}