Public/New-bConnectKioskJob.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
Function New-bConnectKioskJob() {
    <#
        .Synopsis
            Release an job for an endpoint, group or user.
        .Parameter JobDefinitionId
            Valid GUID of an job.
        .Parameter TargetId
            Valid GUID of an endpoint, group or user.
        .Parameter Username
            Valid Username (Principal Name).
            If set, Username replaces TargetId.
        .Outputs
            Boolean
    #>


    [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'low')]
    [OutputType("System.Management.Automations.PSObject","System.Boolean")]
    Param (
        [Parameter(Mandatory=$true)][string]$JobDefinitionId,
        [string]$TargetId,
        [string]$Username
    )

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

        If($Username) {
            $_body += @{
                User = $Username
            }
        } else {
            If($TargetId) {
                $_body += @{
                    TargetId = $TargetId
                }
            }
        }

        if($PSCmdlet.ShouldProcess($_body.EndpointId, "Release the job for specified target.")){
            return Invoke-bConnectPost -Controller "KioskJobs" -Version $_connectVersion -Data $_body
        } else {
            return $false
        }
    } else {
        return $false
    }
}