Public/Get-HypervisorDetails.ps1
<#
.SYNOPSIS Retrieves details of hypervisors from the Citrix Monitor OData service. .DESCRIPTION This function retrieves details of hypervisors from the Citrix Monitor OData service and returns a custom object with the hypervisor name, lifecycle state, creation date, modification date, and deployment state. .PARAMETER DeliveryController Specifies the Delivery Controller hostname or IP address. .EXAMPLE # Retrieve details of hypervisors from the specified Delivery Controller Get-HypervisorDetails -DeliveryController "MyDeliveryController" .NOTES Requires Citrix PowerShell SDK and appropriate administrative credentials. #> function Get-HypervisorDetails { [CmdletBinding()] param ( [Parameter(Mandatory = $true)] [string]$DeliveryController ) # Define the base URI for the OData service $baseUri = "http://$DeliveryController/Citrix/Monitor/OData/v3/Data/Hypervisors" # Construct the query parameters separately for readability $queryParams = "?`$format=json" # Combine them to form the full URI $uri = $baseUri + $queryParams # Determine Deployed state based on DeliveryController name $deployedState = if ($DeliveryController -match "VAUS") { "DR" } else { "Prod" } try { # Invoke the REST method to get the response $response = Invoke-RestMethod -Uri $uri -UseDefaultCredentials # Process each item in the response $response.value | ForEach-Object { # Convert CreatedDate and ModifiedDate to dd/mm/yyyy format $createdDateFormatted = (Get-Date $_.CreatedDate -Format "dd/MM/yyyy") $modifiedDateFormatted = (Get-Date $_.ModifiedDate -Format "dd/MM/yyyy") # Return a custom object with the formatted dates and Deployed state [PSCustomObject]@{ Name = $_.Name LifecycleState = $_.LifecycleState CreatedDate = $createdDateFormatted ModifiedDate = $modifiedDateFormatted Deployed = $deployedState } } } catch { Write-Error "An error occurred: $_" } } |