Public/New-bConnectApplication.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
87
Function New-bConnectApplication() {
    <#
        .Synopsis
            Create a new application.
        .Outputs
            NewEndpoint (see bConnect documentation for more details).
    #>


    [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'low')]
    [OutputType("System.Management.Automations.PSObject","System.Boolean")]
    Param (
        [Parameter(Mandatory=$true)][string]$Name,
        [Parameter(Mandatory=$true)][string]$Vendor,
        [Parameter(Mandatory=$true)][ValidateSet("NT4","Windows2000","WindowsXP","WindowsServer2003","WindowsVista","WindowsServer2008","Windows7","WindowsServer2008R2","WindowsXP_x64","WindowsServer2003_x64","WindowsVista_x64","WindowsServer2008_x64","Windows7_x64","WindowsServer2008R2_x64","Windows8","WindowsServer2012","Windows8_x64","WindowsServer2012_x64","Windows10","Windows10_x64","WindowsServer2016_x64",ignoreCase=$true)][string[]]$ValidForOS,
        [string]$Comment,
        [string]$ParentGuid, # = "C1A25EC3-4207-4538-B372-8D250C5D7908", #guid of "Logical Group" as fallback
        [string]$Version,
        [string]$Category,
        [PSCustomObject]$InstallationData,
        [PSCustomObject]$UninstallationData,
        [string]$ConsistencyChecks,
        [PSCustomObject[]]$ApplicationFile,
        [float]$Cost = 0,
        [ValidateSet("AnyUser","InstallUser","LocalInstallUser","LocalSystem","LoggedOnUser","RegisteredUser","SpecifiedUser",ignoreCase=$true)][string]$SecurityContext,
        [PSCustomObject[]]$Licenses,
        [PSCustomObject[]]$AUT
    )

    $_connectVersion = Get-bConnectVersion
    If($_connectVersion -ge "1.0") {
        $_body = @{
            Name = $Name;
            Vendor = $Vendor;
            ValidForOS = $ValidForOS;
            Cost = $Cost
        }

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

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

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

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

        If($InstallationData) {
            $_body += @{ Installation = $InstallationData }
        }

        If($UninstallationData) {
            $_body += @{ Uninstallation = $UninstallationData }
        }

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

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

        If($Licenses.Count -gt 0) {
            $_body += @{ Licenses = $Licenses }
        }

        If($AUT.Count -gt 0) {
            $_body += @{ EnableAUT = $true; AUT = $AUT }
        }

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