Functions/Public/reservation-service/Get-vRAReservationTemplate.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 |
function Get-vRAReservationTemplate { <# .SYNOPSIS Get a reservation json template .DESCRIPTION Get a reservation json template. This template can then be used to create a new reservation with the same properties .PARAMETER Id The id of the reservation .PARAMETER OutFile The path to an output file .INPUTS System.String .OUTPUTS System.String .EXAMPLE Get-vRAReservationTemplate -Id 75ae3400-beb5-4b0b-895a-0484413c93b1 -OutFile C:\Reservation.json .EXAMPLE Get-vRAReservation -Name Reservation1 | Get-vRAReservationTemplate -OutFile C:\Reservation.json .EXAMPLE Get-vRAReservation -Name Reservation1 | Get-vRAReservationTemplate #> [CmdletBinding(DefaultParameterSetName="Standard")][OutputType('System.String')] Param ( [parameter(Mandatory=$true, ValueFromPipelineByPropertyName)] [ValidateNotNullOrEmpty()] [String]$Id, [parameter(Mandatory=$false)] [ValidateNotNullOrEmpty()] [String]$OutFile ) try { $URI = "/reservation-service/api/reservations/$($Id)" Write-Verbose -Message "Preparing GET to $($URI)" $Response = Invoke-vRARestMethod -Method GET -URI "$($URI)" Write-Verbose -Message "SUCCESS" # --- Remove the id from the response $Response.PSObject.Properties.Remove("id") if ($PSBoundParameters.ContainsKey("OutFile")) { Write-Verbose -Message "Outputting response to $($OutFile)" # --- Output the response to file $Response | ConvertTo-Json -Depth 100 | Out-File -FilePath $OutFile -Force } else { # --- Return the response $Response | ConvertTo-Json -Depth 100 } } catch [Exception]{ throw } } |