Functions/Public/catalog-service/Get-vRAResourceActionRequestTemplate.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
function Get-vRAResourceActionRequestTemplate {
<#
    .SYNOPSIS
    Get the request template of a resource action that the user is entitled to see
    
    .DESCRIPTION
    Get the request template of a resource action that the user is entitled to see
    
    .PARAMETER Id
    The id of the resource action

    .PARAMETER Name
    The name of the resource action

    .INPUTS
    System.String

    .OUTPUTS
    System.String

    .EXAMPLE
    Get-vRAResourceActionRequestTemplate -ActionId "fae08c75-3506-40f6-9c9b-35966fe9125c" -ResourceName vm01
    
    .EXAMPLE
    Get-vRAResourceActionRequestTemplate -ActionId "fae08c75-3506-40f6-9c9b-35966fe9125c" -ResourceId 20402e93-fb1d-4bd9-8a51-b809fbb946fd

#>

[CmdletBinding(DefaultParameterSetName="ByResourceId")][OutputType('System.String')]

    Param (

        [Parameter(Mandatory=$true)]
        [ValidateNotNullOrEmpty()]
        [String]$ActionId,
    
        [Parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,ParameterSetName="ByResourceId")]
        [ValidateNotNullOrEmpty()]
        [String[]]$ResourceId,

        [Parameter(Mandatory=$true,ParameterSetName="ByResourceName")]
        [ValidateNotNullOrEmpty()]
        [String[]]$ResourceName
           
    )
    
    Begin {

        xRequires -Version 7.0

    }
 
    Process {

        try {


            switch ($PSCmdlet.ParameterSetName) {

                'ByResourceId' {

                    foreach ($Id in $ResourceId) {

                        _requestResourceActionTemplate -ResourceId $Id -ActionId $ActionId

                    }

                    break

                }

                'ByResourceName' {

                    foreach ($Name in $ResourceName) {

                        # --- Get the resource id
                        Write-verbose -Message "Retrieving Id for resource $($Name)"
                        $Resource = Get-vRAResource -Name $ResourceName
                        $ResourceId = $Resource.ResourceId

                        _requestResourceActionTemplate -ResourceId $ResourceId -ActionId $ActionId

                    }

                    break

                }

            }

        }
        catch [Exception]{

            throw

        }

    }

    End {
        
    }

}

function _requestResourceActionTemplate($ResourceId, $ActionId) {
<#

    Private function to invoke the resource action request template
    request

#>


    $URI = "/catalog-service/api/consumer/resources/$($ResourceId)/actions/$($ActionId)/requests/template"

    $Response = Invoke-vRARestMethod -Method GET -URI $URI -Verbose:$VerbosePreference

    $Response | ConvertTo-Json -Depth 100

}