Functions/Public/content-management-service/DEPRECATED-New-vRAContentPackage.psm1

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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
function New-vRAContentPackage {
<#
    .SYNOPSIS
    Create a vRA Content Package
    
    .DESCRIPTION
    Create a vRA ContentPackage
    
    .PARAMETER Name
    Content Package Name
    
    .PARAMETER Description
    Content Package Description

    .PARAMETER BlueprintId
    Blueprint Ids to include in the Content Package

    .PARAMETER BlueprintName
    Blueprint Names to include in the Content Package

    .PARAMETER JSON
    Body text to send in JSON format

    .INPUTS
    System.String.

    .OUTPUTS
    System.Management.Automation.PSObject

    .EXAMPLE
    New-vRAContentPackage -Name ContentPackage01 -Description "This is Content Package 01" -BlueprintId "58e10956-172a-48f6-9373-932f99eab37a","0c74b085-dbc1-4fea-9cbf-a1601f668a1f"

    .EXAMPLE
    New-vRAContentPackage -Name ContentPackage01 -Description "This is Content Package 01" -BlueprintName "Blueprint01","Blueprint02"
    
    .EXAMPLE
    $JSON = @"
    {
        "name":"ContentPackage01",
        "description":"This is Content Package 01",
        "contents":[ "58e10956-172a-48f6-9373-932f99eab37a","0c74b085-dbc1-4fea-9cbf-a1601f668a1f" ]
    }
    "@
    $JSON | New-vRAContentPackage
#>

[CmdletBinding(SupportsShouldProcess,ConfirmImpact="Low",DefaultParameterSetName="ById")][OutputType('System.Management.Automation.PSObject')]

    Param (

    [parameter(Mandatory=$true,ParameterSetName="ById")]
    [parameter(Mandatory=$true,ParameterSetName="ByName")]
    [ValidateNotNullOrEmpty()]
    [String]$Name,
    
    [parameter(Mandatory=$false)]
    [ValidateNotNullOrEmpty()]
    [String]$Description,

    [parameter(Mandatory=$true,ParameterSetName="ById")]
    [ValidateNotNullOrEmpty()]
    [String[]]$BlueprintId,

    [parameter(Mandatory=$true,ParameterSetName="ByName")]
    [ValidateNotNullOrEmpty()]
    [String[]]$BlueprintName,

    [parameter(Mandatory=$true,ValueFromPipeline=$true,ParameterSetName="JSON")]
    [ValidateNotNullOrEmpty()]
    [String]$JSON
    )    

    begin {

        Write-Warning -Message "This command is deprecated and will be removed in a future release. Please use New-vRAPackage instead."

        # --- Test for vRA API version
        xRequires -Version 7.0
    }
    
    process {

        switch ($PsCmdlet.ParameterSetName) 
        { 
            "ById"  {                

                $Object = [pscustomObject] @{

                    name = $Name
                    description = $Description
                    contents = @()
                }

                foreach ($Id in $BlueprintId) {

                    $Object.contents += $Id

                }

                $Body = $Object | ConvertTo-Json                    

                break
            }

            "ByName"  {
                
                $Object = [pscustomObject] @{

                    name = $Name
                    description = $Description
                    contents = @()
                }

                foreach ($BPName in $BlueprintName) {

                    $Id = (Get-vRABlueprint -Name $BPName).Id

                    $Object.contents += $Id

                }

                $Body = $Object | ConvertTo-Json 
                
                break
            }

            "JSON"  {

                $Data = ($JSON | ConvertFrom-Json)
        
                $Body = $JSON
                $Name = $Data.name  
                
                break
            }
        }

        if ($PSCmdlet.ShouldProcess($Name)){

            $URI = "/content-management-service/api/packages"

            # --- Run vRA REST Request
            Invoke-vRARestMethod -Method POST -URI $URI -Body $Body | Out-Null

            # --- Output the Successful Result
            Get-vRAContentPackage -Name $Name
        } 
    }
    end {
        
    }
}