From 2a93e4a49b7df07f7a2a4ee290afa7f6b9c81e91 Mon Sep 17 00:00:00 2001 From: Marcus Puckett Date: Mon, 14 Sep 2020 15:27:37 -0400 Subject: [PATCH] Fix Get-vRABluerpint Fix issues with Get-vRABlueprint (doesn't support OData filters). --- .../Public/blueprint/Get-vRABlueprint.ps1 | 29 +++--- .../blueprint/Get-vRABlueprintVersion.ps1 | 97 +++++++++++++++++++ src/PowervRA.psd1 | 2 +- 3 files changed, 110 insertions(+), 18 deletions(-) create mode 100644 src/Functions/Public/blueprint/Get-vRABlueprintVersion.ps1 diff --git a/src/Functions/Public/blueprint/Get-vRABlueprint.ps1 b/src/Functions/Public/blueprint/Get-vRABlueprint.ps1 index 723412bd..2f65415c 100644 --- a/src/Functions/Public/blueprint/Get-vRABlueprint.ps1 +++ b/src/Functions/Public/blueprint/Get-vRABlueprint.ps1 @@ -80,18 +80,11 @@ function Get-vRABlueprint { foreach ($BlueprintId in $Id){ - $URI = "$($APIUrl)?`$filter=id eq '$($BlueprintId)'" + $URI = "$($APIUrl)/$($BlueprintId)" $Response = Invoke-vRARestMethod -Method GET -URI $URI -Verbose:$VerbosePreference - foreach ($Blueprint in $Response.content) { - # Get individual blueprint link - $BlueprintSelfLink = $blueprint.selfLink - - # Get full blueprint resource info - $FullBlueprints = Invoke-vRARestMethod -Method GET -URI $BlueprintSelfLink -Verbose:$VerbosePreference - foreach ($FullBlueprint in $FullBlueprints){ - CalculateOutput $FullBlueprint - } + foreach($Blueprint in $Response){ + CalculateOutput $Blueprint } } @@ -102,17 +95,19 @@ function Get-vRABlueprint { foreach ($BlueprintName in $Name){ - $URI = "$($APIUrl)?`$filter=name eq '$($BlueprintName)'" + $URI = "$($APIUrl)" $Response = Invoke-vRARestMethod -Method GET -URI $URI -Verbose:$VerbosePreference foreach ($Blueprint in $Response.content) { - # Get individual blueprint link - $BlueprintSelfLink = $blueprint.selfLink + if($Blueprint.name -eq $BlueprintName){ + # Get individual blueprint link + $BlueprintSelfLink = $blueprint.selfLink - # Get full blueprint resource info - $FullBlueprints = Invoke-vRARestMethod -Method GET -URI $BlueprintSelfLink -Verbose:$VerbosePreference - foreach ($FullBlueprint in $FullBlueprints){ - CalculateOutput $FullBlueprint + # Get full blueprint resource info + $FullBlueprints = Invoke-vRARestMethod -Method GET -URI $BlueprintSelfLink -Verbose:$VerbosePreference + foreach ($FullBlueprint in $FullBlueprints){ + CalculateOutput $FullBlueprint + } } } } diff --git a/src/Functions/Public/blueprint/Get-vRABlueprintVersion.ps1 b/src/Functions/Public/blueprint/Get-vRABlueprintVersion.ps1 new file mode 100644 index 00000000..86b70f54 --- /dev/null +++ b/src/Functions/Public/blueprint/Get-vRABlueprintVersion.ps1 @@ -0,0 +1,97 @@ +function Get-vRABlueprintVersion { + <# + .SYNOPSIS + Get a vRA Blueprint's Versions + + .DESCRIPTION + Get a vRA Blueprint's Versions + + .PARAMETER Blueprint + The vRA Blueprint object as returned by Get-vRABlueprint + + .INPUTS + System.String + + .OUTPUTS + System.Management.Automation.PSObject + + .EXAMPLE + Get-vRABlueprint | Get-vRABlueprintVersion + + .EXAMPLE + Get-vRABlueprintVersion -Blueprint (Get-vRABlueprint -Id '3492a6e8-r5d4-1293-b6c4-39037ba693f9') + + .EXAMPLE + Get-vRABlueprintVersion -Blueprint (Get-vRABlueprint -Name 'TestBlueprint') + + #> + [CmdletBinding(DefaultParameterSetName="Standard")][OutputType('System.Management.Automation.PSObject')] + + Param ( + + [Parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,ParameterSetName="Blueprint")] + [ValidateNotNullOrEmpty()] + [PSCustomObject[]]$Blueprint + ) + + begin { + $APIUrl = '/blueprint/api/blueprints' + + function CalculateOutput([PSCustomObject]$BlueprintVersion) { + + [PSCustomObject] @{ + Id = $BlueprintVersion.id + CreatedAt = $BlueprintVersion.createdAt + CreatedBy = $BlueprintVersion.createdBy + UpdatedAt = $BlueprintVersion.updatedAt + UpdatedBy = $BlueprintVersion.updatedBy + OrganizationId = $BlueprintVersion.orgId + ProjectId = $BlueprintVersion.projectId + ProjectName = $BlueprintVersion.projectName + SelfLink = $BlueprintVersion.selfLink + BlueprintId = $BlueprintVersion.blueprintId + Name = $BlueprintVersion.name + Description = $BlueprintVersion.description + Version = $BlueprintVersion.version + Status = $BlueprintVersion.status + VersionDescription = $BlueprintVersion.versionDescription + VersionChangeLog = $BlueprintVersion.versionChangeLog + Valid = $BlueprintVersion.valid + } + } + } + + process { + + try { + + switch ($PsCmdlet.ParameterSetName) { + + # --- Get BlueprintVersion from Blueprint object + 'Blueprint' { + + foreach ($Blueprintobj in $Blueprint){ + + $URI = "$($APIUrl)/$($Blueprintobj.Id)/versions" + $Response = Invoke-vRARestMethod -Method GET -URI $URI -Verbose:$VerbosePreference + + foreach($version in $Response.content){ + CalculateOutput $version + } + } + + break + } + } + } + catch [Exception]{ + + throw + } + } + + end { + + } + } + \ No newline at end of file diff --git a/src/PowervRA.psd1 b/src/PowervRA.psd1 index 08e78e5d..b1303e13 100644 --- a/src/PowervRA.psd1 +++ b/src/PowervRA.psd1 @@ -69,7 +69,7 @@ PowerShellVersion = '5.1' # NestedModules = @() # Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export. -FunctionsToExport = @('Connect-vRAServer','Disconnect-vRAServer','Get-vRAAPIVersion','Get-vRABlockDevice','Get-vRABlueprint','Get-vRACatalogItem','Get-vRACloudAccount','Get-vRACloudZone','Get-vRACodeStreamExecution','Get-vRACodeStreamPipeline','Get-vRACodeStreamVariable','Get-vRAContentSource','Get-vRADeployment','Get-vRAExternalNetworkIPRange','Get-vRAFabricAWSVolumeType','Get-vRAFabricAzureStorageAccount','Get-vRAFabricCompute','Get-vRAFabricImage','Get-vRAFabricNetwork','Get-vRAFlavorProfile','Get-vRAImageProfile','Get-vRALoadBalancer','Get-vRAMachine','Get-vRAMachineDisk','Get-vRANetwork','Get-vRANetworkDomain','Get-vRANetworkIPRange','Get-vRANetworkProfile','Get-vRAOnboardingDeployment','Get-vRAOnboardingPlan','Get-vRAOnboardingPlanExecution','Get-vRAOnboardingResource','Get-vRAProject','Get-vRARegion','Get-vRARegionEnumerationvSphere','Get-vRARequest','Get-vRASecurityGroup','Get-vRAStorageProfile','Get-vRATag','Get-vRAvSphereFabricDatastore','Get-vRAFabricNetwork','Get-vRAvSphereFabricStoragePolicy','Invoke-vRAOnboardingPlan','Invoke-vRARestMethod','New-vRACloudAccountAzure','New-vRACloudAccountGCP','New-vRACloudAccountvSphere','New-vRAMachineAttachedDisk','New-vRAOnboardingDeployment','New-vRAOnboardingPlan','New-vRAOnboardingResource','New-vRAProject','New-vRAVirtualDisk','Remove-vRACloudAccount','Remove-vRACodeStreamExecution','Remove-vRACodeStreamVariable','Remove-vRAOnboardingDeployment','Remove-vRAOnboardingPlan','Remove-vRAOnboardingResource','Remove-vRAProject','Resize-vRAMachine','Restart-vRAMachine','Restart-vRAMachineGuestOS','Start-vRAMachine','Stop-vRAMachine','Stop-vRAMachineGuestOS','Suspend-vRAMachine','Update-vRACodeStreamVariable') +FunctionsToExport = @('Connect-vRAServer','Disconnect-vRAServer','Get-vRAAPIVersion','Get-vRABlockDevice','Get-vRABlueprint','Get-vRABlueprintVersion','Get-vRACatalogItem','Get-vRACloudAccount','Get-vRACloudZone','Get-vRACodeStreamExecution','Get-vRACodeStreamPipeline','Get-vRACodeStreamVariable','Get-vRAContentSource','Get-vRADeployment','Get-vRAExternalNetworkIPRange','Get-vRAFabricAWSVolumeType','Get-vRAFabricAzureStorageAccount','Get-vRAFabricCompute','Get-vRAFabricImage','Get-vRAFabricNetwork','Get-vRAFlavorProfile','Get-vRAImageProfile','Get-vRALoadBalancer','Get-vRAMachine','Get-vRAMachineDisk','Get-vRANetwork','Get-vRANetworkDomain','Get-vRANetworkIPRange','Get-vRANetworkProfile','Get-vRAOnboardingDeployment','Get-vRAOnboardingPlan','Get-vRAOnboardingPlanExecution','Get-vRAOnboardingResource','Get-vRAProject','Get-vRARegion','Get-vRARegionEnumerationvSphere','Get-vRARequest','Get-vRASecurityGroup','Get-vRAStorageProfile','Get-vRATag','Get-vRAvSphereFabricDatastore','Get-vRAFabricNetwork','Get-vRAvSphereFabricStoragePolicy','Invoke-vRAOnboardingPlan','Invoke-vRARestMethod','New-vRACloudAccountAzure','New-vRACloudAccountGCP','New-vRACloudAccountvSphere','New-vRAMachineAttachedDisk','New-vRAOnboardingDeployment','New-vRAOnboardingPlan','New-vRAOnboardingResource','New-vRAProject','New-vRAVirtualDisk','Remove-vRACloudAccount','Remove-vRACodeStreamExecution','Remove-vRACodeStreamVariable','Remove-vRAOnboardingDeployment','Remove-vRAOnboardingPlan','Remove-vRAOnboardingResource','Remove-vRAProject','Resize-vRAMachine','Restart-vRAMachine','Restart-vRAMachineGuestOS','Start-vRAMachine','Stop-vRAMachine','Stop-vRAMachineGuestOS','Suspend-vRAMachine','Update-vRACodeStreamVariable') # Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. CmdletsToExport = @()