New HV Functions for vCenter and BaseImage
This commit is contained in:
@@ -94,6 +94,159 @@ function Get-VcenterID {
|
||||
return $virtualCenterId
|
||||
}
|
||||
|
||||
function Get-HVvCenterServer {
|
||||
<#
|
||||
.Synopsis
|
||||
Gets a list of all configured vCenter Servers
|
||||
|
||||
.DESCRIPTION
|
||||
Queries and returns the vCenter Servers configured for the pod of the specified HVServer.
|
||||
|
||||
.PARAMETER HvServer
|
||||
Reference to Horizon View Server to query the virtual machines from. If the value is not passed or null then
|
||||
first element from global:DefaultHVServers would be considered inplace of hvServer
|
||||
|
||||
.PARAMETER Name
|
||||
A string value to query a vCenter Server by Name, if it is known.
|
||||
|
||||
.EXAMPLE
|
||||
Get-HVvCenterServer
|
||||
|
||||
.EXAMPLE
|
||||
Get-HVvCenterServer -Name 'vCenter1'
|
||||
|
||||
.OUTPUTS
|
||||
Returns array of object type VMware.Hv.VirtualCenterInfo
|
||||
|
||||
.NOTES
|
||||
Author : Matt Frey.
|
||||
Author email : mfrey@vmware.com
|
||||
Version : 1.0
|
||||
|
||||
===Tested Against Environment====
|
||||
Horizon View Server Version : 7.7
|
||||
PowerCLI Version : PowerCLI 11.2.0
|
||||
PowerShell Version : 5.1
|
||||
#>
|
||||
|
||||
param(
|
||||
[Parameter(Mandatory = $false)]
|
||||
$HvServer = $null,
|
||||
|
||||
[Parameter(Mandatory = $false)]
|
||||
[string]$Name = $null
|
||||
)
|
||||
|
||||
begin {
|
||||
$services = Get-ViewAPIService -hvServer $hvServer
|
||||
|
||||
if ($null -eq $services) {
|
||||
Write-Error "Could not retrieve ViewApi services from connection object"
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
process {
|
||||
|
||||
if ($null -ne $PSBoundParameters.Name) {
|
||||
$vCenterList = $services.VirtualCenter.VirtualCenter_List() | Where-Object {$_.ServerSpec.ServerName -eq $Name}
|
||||
} else {
|
||||
$vCenterList = $services.VirtualCenter.VirtualCenter_List()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
end {
|
||||
|
||||
return $vCenterList
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function Get-HVvCenterServerHealth {
|
||||
<#
|
||||
.Synopsis
|
||||
Gets a the health info for a given vCenter Server.
|
||||
|
||||
.DESCRIPTION
|
||||
Queries and returns the VirtualCenterHealthInfo specified HVServer.
|
||||
|
||||
.PARAMETER HvServer
|
||||
Reference to Horizon View Server to query the virtual machines from. If the value is not passed or null then
|
||||
first element from global:DefaultHVServers would be considered inplace of hvServer
|
||||
|
||||
.PARAMETER VirtualCenter
|
||||
A parameter to specify which vCenter Server to check health for. If not specified, this function will return the
|
||||
health info for all vCenter Servers.
|
||||
|
||||
.EXAMPLE
|
||||
Get-HVvCenterServerHealth -VirtualCenter 'vCenter1'
|
||||
|
||||
.EXAMPLE
|
||||
Get-HVvCenterServerHealth -VirtualCenter $vCenter1
|
||||
|
||||
.EXAMPLE
|
||||
Get-HVvCenterServerHealth
|
||||
|
||||
.OUTPUTS
|
||||
Returns array of object type VMware.Hv.VirtualCenterInfo
|
||||
|
||||
.NOTES
|
||||
Author : Matt Frey.
|
||||
Author email : mfrey@vmware.com
|
||||
Version : 1.0
|
||||
|
||||
===Tested Against Environment====
|
||||
Horizon View Server Version : 7.7
|
||||
PowerCLI Version : PowerCLI 11.2.0
|
||||
PowerShell Version : 5.1
|
||||
#>
|
||||
|
||||
param(
|
||||
[Parameter(Mandatory = $false)]
|
||||
$HvServer = $null,
|
||||
|
||||
[Parameter(Mandatory = $false)]
|
||||
$VirtualCenter = $null
|
||||
)
|
||||
|
||||
begin {
|
||||
$services = Get-ViewAPIService -hvServer $hvServer
|
||||
|
||||
if ($null -eq $services) {
|
||||
Write-Error "Could not retrieve ViewApi services from connection object"
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
process {
|
||||
|
||||
if ($null -eq $PSBoundParameters.VirtualCenter) {
|
||||
$VirtualCenterHealth = $services.VirtualCenterHealth.VirtualCenterHealth_List()
|
||||
} else {
|
||||
$objType = $VirtualCenter.getType() | Select-Object -ExpandProperty Name
|
||||
Switch ($objType) {
|
||||
'String' {
|
||||
$VirtualCenterHealth = $services.VirtualCenterHealth.VirtualCenterHealth_Get($(Get-HVvCenterServer -Name $VirtualCenter | Select-Object -ExpandProperty Id))
|
||||
}
|
||||
'VirtualCenterInfo' {
|
||||
$VirtualCenterHealth = $services.VirtualCenterHealth.VirtualCenterHealth_Get($($VirtualCenter | Select-Object -ExpandProperty Id))
|
||||
}
|
||||
'VirtualCenterId' {
|
||||
$VirtualCenterHealth = $services.VirtualCenterHealth.VirtualCenterHealth_Get($VirtualCenter)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
end {
|
||||
|
||||
return $VirtualCenterHealth
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function Get-JsonObject {
|
||||
param(
|
||||
[Parameter(Mandatory = $true)]
|
||||
@@ -462,8 +615,6 @@ function Add-HVRDSServer {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function Connect-HVEvent {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
@@ -2790,7 +2941,6 @@ function Test-HVFarmSpec {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function Get-HVFarmProvisioningData {
|
||||
param(
|
||||
[Parameter(Mandatory = $false)]
|
||||
@@ -2865,7 +3015,6 @@ function Get-HVFarmProvisioningData {
|
||||
return $vmObject
|
||||
}
|
||||
|
||||
|
||||
function Get-HVFarmStorageObject {
|
||||
param(
|
||||
|
||||
@@ -2933,7 +3082,6 @@ function Get-HVFarmStorageObject {
|
||||
return $storageObject
|
||||
}
|
||||
|
||||
|
||||
function Get-HVFarmNetworkSetting {
|
||||
param(
|
||||
[Parameter(Mandatory = $false)]
|
||||
@@ -2945,7 +3093,6 @@ function Get-HVFarmNetworkSetting {
|
||||
return $networkObject
|
||||
}
|
||||
|
||||
|
||||
function Get-HVFarmCustomizationSetting {
|
||||
param(
|
||||
[Parameter(Mandatory = $false)]
|
||||
@@ -3078,7 +3225,6 @@ function Get-FarmSpec {
|
||||
return $farm_spec_helper.getDataObject()
|
||||
}
|
||||
|
||||
|
||||
function New-HVPool {
|
||||
<#
|
||||
.Synopsis
|
||||
@@ -4922,7 +5068,6 @@ function Get-HVPoolProvisioningData {
|
||||
return $vmObject
|
||||
}
|
||||
|
||||
|
||||
function Get-HVHostOrClusterID {
|
||||
<#
|
||||
.Synopsis
|
||||
@@ -6902,6 +7047,239 @@ function Get-Machine ($Pool,$MachineList) {
|
||||
return $machines
|
||||
}
|
||||
|
||||
function Get-HVBaseImageVM {
|
||||
<#
|
||||
.Synopsis
|
||||
Gets a list of compatible base image virtual machines.
|
||||
|
||||
.DESCRIPTION
|
||||
Queries and returns BaseImageVmInfo for the specified vCenter Server.
|
||||
|
||||
.PARAMETER HvServer
|
||||
Reference to Horizon View Server to query the virtual machines from. If the value is not passed or null then
|
||||
first element from global:DefaultHVServers would be considered in place of hvServer.
|
||||
|
||||
.PARAMETER VirtualCenter
|
||||
A parameter to specify which vCenter Server to check base image VMs for. It can be specified as a String,
|
||||
containing the name of the vCenter, or as a vCenter object as returned by Get-HVvCenterServer. If the value is
|
||||
not passed or null then first element returned from Get-HVvCenterServer would be considered in place of VirtualCenter.
|
||||
|
||||
.PARAMETER ImageType
|
||||
A parameter to define the type of compatability to check the base image VM list against. Valid options are 'VDI', 'RDS', or 'ALL'
|
||||
'VDI' will return all desktop compatible Base Image VMs.
|
||||
'RDS' will return all RDSH compatible Base Image VMs.
|
||||
'ALL' will return all Base Image VMs, regardless of compatibility.
|
||||
The default value is 'ALL'.
|
||||
|
||||
.PARAMETER Name
|
||||
The name of a virtual machine (if known), to filter Base Image VMs on. Wildcards are accepted. If Name is specified, then ImageType
|
||||
is not considered for filtering.
|
||||
|
||||
.EXAMPLE
|
||||
Get-HVBaseImageVM -VirtualCenter 'vCenter1' -ImageType VDI
|
||||
|
||||
.EXAMPLE
|
||||
Get-HVBaseImageVM -VirtualCenter $vCenter1 -ImageType ALL
|
||||
|
||||
.EXAMPLE
|
||||
Get-HVBaseImageVM -Name '*WIN10*'
|
||||
|
||||
.OUTPUTS
|
||||
Returns array of object type VMware.Hv.BaseImageVmInfo
|
||||
|
||||
.NOTES
|
||||
Author : Matt Frey.
|
||||
Author email : mfrey@vmware.com
|
||||
Version : 1.0
|
||||
|
||||
===Tested Against Environment====
|
||||
Horizon View Server Version : 7.7
|
||||
PowerCLI Version : PowerCLI 11.2.0
|
||||
PowerShell Version : 5.1
|
||||
#>
|
||||
|
||||
[cmdletbinding(
|
||||
DefaultParameterSetName='ImageType'
|
||||
)]
|
||||
|
||||
param(
|
||||
[Parameter(Mandatory = $false)]
|
||||
$HvServer = $null,
|
||||
|
||||
[Parameter(Mandatory = $false)]
|
||||
$VirtualCenter = $null,
|
||||
|
||||
[Parameter(Mandatory = $false,ParameterSetName = 'ImageType')]
|
||||
[ValidateSet('VDI','RDS','ALL')]
|
||||
$ImageType = 'VDI',
|
||||
|
||||
[Parameter(Mandatory = $false,ParameterSetName = 'Name')]
|
||||
[string]$Name = $null
|
||||
)
|
||||
|
||||
begin {
|
||||
$services = Get-ViewAPIService -hvServer $hvServer
|
||||
|
||||
if ($null -eq $services) {
|
||||
Write-Error "Could not retrieve ViewApi services from connection object"
|
||||
break
|
||||
}
|
||||
|
||||
if ($null -eq $PSBoundParameters.VirtualCenter) {
|
||||
$VirtualCenterId = Get-HVvCenterServer | Select-Object -First 1 -ExpandProperty Id
|
||||
} else {
|
||||
$objType = $VirtualCenter.getType() | Select-Object -ExpandProperty Name
|
||||
Switch ($objType) {
|
||||
'String' {
|
||||
$VirtualCenterId = Get-HVvCenterServer -Name $VirtualCenter | Select-Object -ExpandProperty Id
|
||||
}
|
||||
'VirtualCenterInfo' {
|
||||
$VirtualCenterId = $VirtualCenter | Select-Object -ExpandProperty Id
|
||||
}
|
||||
'VirtualCenterId' {
|
||||
$VirtualCenterId = $VirtualCenter
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
process {
|
||||
|
||||
$BaseImageVMList = $services.BaseImageVM.BaseImageVM_List($VirtualCenterId)
|
||||
|
||||
#For all conditions, see https://vdc-download.vmware.com/vmwb-repository/dcr-public/3721109b-48a5-4ffb-a0ad-6d6a44f2f288/ff45dfca-1050-4265-93ef-4e7d702322e4/vdi.utils.virtualcenter.BaseImageVm.BaseImageVmIncompatibleReasons.html
|
||||
|
||||
If ($null -ne $PSBoundParameters.Name) {
|
||||
$CompatibleBaseImageVMs = $BaseImageVMList | Where-Object {$_.Name -like $Name}
|
||||
} Else {
|
||||
Switch ($ImageType) {
|
||||
|
||||
'VDI' {
|
||||
$CompatibleBaseImageVMs = $BaseImageVMList | Where-Object {
|
||||
($_.IncompatibleReasons.InUseByDesktop -eq $false) -and
|
||||
($_.IncompatibleReasons.InUseByLinkedCloneDesktop -eq $false) -and
|
||||
($_.IncompatibleReasons.ViewComposerReplica -eq $false) -and
|
||||
($_.IncompatibleReasons.UnsupportedOS -eq $false) -and
|
||||
($_.IncompatibleReasons.NoSnapshots -eq $false) -and
|
||||
(($null -eq $_.IncompatibleReasons.InstantInternal) -or ($_.IncompatibleReasons.InstantInternal -eq $false))
|
||||
}
|
||||
}
|
||||
'RDS' {
|
||||
$CompatibleBaseImageVMs = $BaseImageVMList | Where-Object {
|
||||
($_.IncompatibleReasons.InUseByDesktop -eq $false) -and
|
||||
($_.IncompatibleReasons.InUseByLinkedCloneDesktop -eq $false) -and
|
||||
($_.IncompatibleReasons.ViewComposerReplica -eq $false) -and
|
||||
($_.IncompatibleReasons.UnsupportedOSForLinkedCloneFarm -eq $false) -and
|
||||
($_.IncompatibleReasons.NoSnapshots -eq $false) -and
|
||||
(($null -eq $_.IncompatibleReasons.InstantInternal) -or ($_.IncompatibleReasons.InstantInternal -eq $false))
|
||||
}
|
||||
}
|
||||
'ALL' {
|
||||
$CompatibleBaseImageVMs = $BaseImageVMList
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
end {
|
||||
|
||||
return $CompatibleBaseImageVMs
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function Get-HVBaseImageSnapshot {
|
||||
<#
|
||||
.Synopsis
|
||||
Gets a list of compatible base image virtual machines.
|
||||
|
||||
.DESCRIPTION
|
||||
Queries and returns BaseImageVmInfo for the specified vCenter Server.
|
||||
|
||||
.PARAMETER HvServer
|
||||
Reference to Horizon View Server to query the virtual machines from. If the value is not passed or null then
|
||||
first element from global:DefaultHVServers would be considered in place of hvServer.
|
||||
|
||||
.PARAMETER BaseImageVM
|
||||
The BaseImageVM to query snapshots for. This parameter is required. Wildcards are accepted. This parameter also supports
|
||||
pipeline operations with Get-HVBaseImageVM
|
||||
|
||||
.EXAMPLE
|
||||
Get-HVBaseImageSnapshots -BaseImageVM 'WIN10-BaseImage'
|
||||
|
||||
.EXAMPLE
|
||||
Get-HVBaseImageSnapshots -BaseImageVM '*WIN10*'
|
||||
|
||||
.EXAMPLE
|
||||
Get-HVBaseImageVM -Name 'WIN10-BaseImage' | Get-HVBaseImageSnapshots
|
||||
|
||||
.OUTPUTS
|
||||
Array of object type VMware.Hv.BaseImageSnapshotInfo
|
||||
|
||||
.NOTES
|
||||
Author : Matt Frey.
|
||||
Author email : mfrey@vmware.com
|
||||
Version : 1.0
|
||||
|
||||
===Tested Against Environment====
|
||||
Horizon View Server Version : 7.7
|
||||
PowerCLI Version : PowerCLI 11.2.0
|
||||
PowerShell Version : 5.1
|
||||
#>
|
||||
|
||||
[cmdletbinding(
|
||||
DefaultParameterSetName='ImageType'
|
||||
)]
|
||||
|
||||
param(
|
||||
[Parameter(Mandatory = $false)]
|
||||
$HvServer = $null,
|
||||
|
||||
[Parameter(Mandatory = $true,ValueFromPipeLine=$true)]
|
||||
$BaseImageVM = $null
|
||||
)
|
||||
|
||||
begin {
|
||||
$services = Get-ViewAPIService -hvServer $hvServer
|
||||
|
||||
if ($null -eq $services) {
|
||||
Write-Error "Could not retrieve ViewApi services from connection object"
|
||||
break
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
process {
|
||||
|
||||
if ($null -ne $PSBoundParameters.BaseImageVM) {
|
||||
$objType = $BaseImageVM.getType() | Select-Object -ExpandProperty Name
|
||||
Switch ($objType) {
|
||||
'String' {
|
||||
$BaseImageVMObj = Get-HVBaseImageVM -Name $BaseImageVM
|
||||
}
|
||||
'BaseImageVMInfo' {
|
||||
$BaseImageVMObj = $BaseImageVM
|
||||
}
|
||||
'Object[]' {
|
||||
Write-Error 'This function cannot accept an array of Base Image VMs. You must specify only a single Base Image VM.'
|
||||
Break
|
||||
}
|
||||
}
|
||||
$BaseImageSnapshotList = $services.BaseImageSnapshot.BaseImageSnapshot_List($BaseImageVMObj.Id)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
end {
|
||||
|
||||
return $BaseImageSnapshotList
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function Set-HVPoolSpec {
|
||||
param(
|
||||
[Parameter(Mandatory = $true)]
|
||||
@@ -11579,5 +11957,7 @@ Export-ModuleMember -Function Get-HVGlobalSettings, Set-HVApplicationIcon, Remov
|
||||
Export-ModuleMember -Function Get-HVResourceStructure, Get-HVLocalSession, Get-HVGlobalSession
|
||||
# Event Database related
|
||||
Export-ModuleMember -Function Get-HVEventDatabase, Set-HVEventDatabase, Clear-HVEventDatabase, Get-HVEvent, Connect-HVEvent, Disconnect-HVEvent
|
||||
# vCenter Server related
|
||||
Export-ModuleMember -Function Get-HVvCenterServer, Get-HVvCenterServerHealth
|
||||
# Misc/other related
|
||||
Export-ModuleMember -Function Get-HVlicense, Set-HVlicense, Get-HVHealth, Set-HVInstantCloneMaintenance
|
||||
Export-ModuleMember -Function Get-HVlicense, Set-HVlicense, Get-HVHealth, Set-HVInstantCloneMaintenance, Get-HVBaseImageVM, Get-HVBaseImageVMSnapshot
|
||||
Reference in New Issue
Block a user