Functions/Public/reservation-service/Remove-vRAReservation.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
88
89
90
91
92
93
94
95
96
97
98
99
function Remove-vRAReservation {
<#
    .SYNOPSIS
    Remove a reservation
    
    .DESCRIPTION
    Remove a reservation
    
    .PARAMETER Id
    The id of the reservation

    .PARAMETER Name
    The name of the reservation

    .INPUTS
    System.String

    .EXAMPLE
    Remove-vRAReservation -Name Reservation1

    .EXAMPLE
    Remove-vRAReservation -Id 75ae3400-beb5-4b0b-895a-0484413c93b1

    .EXAMPLE
    Get-vRAReservation -Name Reservation1 | Remove-vRAReservation

#>

[CmdletBinding(SupportsShouldProcess,ConfirmImpact="High",DefaultParameterSetName="ById")]

    Param (

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

    [parameter(Mandatory=$true, ParameterSetName="ByName")]
    [ValidateNotNullOrEmpty()]
    [String[]]$Name   
       
    )
    
    begin {}
    
    process {    

        try {

            switch ($PSCmdlet.ParameterSetName) {

                'ById' {

                    foreach ($ReservationId in $Id) {

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

                            $URI = "/reservation-service/api/reservations/$($ReservationId)"
            
                            Invoke-vRARestMethod -Method DELETE -URI "$($URI)" -Verbose:$VerbosePreference | Out-Null
                            
                        }

                    }

                    break

                }

                'ByName' {

                    foreach ($ReservationName in $Name) {

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

                            $ReservationId = (Get-vRAReservation -Name $ReservationName).id

                            $URI = "/reservation-service/api/reservations/$($ReservationId)"
            
                            Invoke-vRARestMethod -Method DELETE -URI "$($URI)"  -Verbose:$VerbosePreference | Out-Null

                        }

                    }

                    break

                }
  
            }
    
        }
        catch [Exception]{
        
            throw

        }
        
    }   
     
}