Merge pull request #166 from Magneet/master
Multiple fixes, removal and new functions in vmware.hv.helper
This commit is contained in:
@@ -8018,9 +8018,11 @@ function Get-HVEntitlement {
|
||||
$doaminFilter = Get-HVQueryFilter 'base.domain' -Eq $Domain
|
||||
$AndFilter += $doaminFilter
|
||||
}
|
||||
$IsGroup = ($Type -eq 'Group')
|
||||
$groupFilter = Get-HVQueryFilter 'base.group' -Eq $IsGroup
|
||||
$AndFilter += $groupFilter
|
||||
if ($type -eq 'group'){
|
||||
$IsGroup = ($Type -eq 'Group')
|
||||
$groupFilter = Get-HVQueryFilter 'base.group' -Eq $IsGroup
|
||||
$AndFilter += $groupFilter
|
||||
}
|
||||
$info = $services.PodFederation.PodFederation_get()
|
||||
$cpaEnabled = ("ENABLED" -eq $info.localPodStatus.status)
|
||||
switch($ResourceType) {
|
||||
@@ -9185,68 +9187,67 @@ function Remove-HVGlobalEntitlement {
|
||||
|
||||
}
|
||||
|
||||
function Get-HVPodSession {
|
||||
function Get-HVGlobalSession {
|
||||
<#
|
||||
.Synopsis
|
||||
Gets the total amount of sessions for all Pods in a Federation
|
||||
.SYNOPSIS
|
||||
Provides a list with all Global sessions in a Cloud Pod Architecture
|
||||
|
||||
.DESCRIPTION
|
||||
Gets the total amout of current sessions (connected and disconnected) for all Pods in a Federation (CPA)
|
||||
based on the global query service.
|
||||
The default object response is used which contains both success and fault information as well as the
|
||||
session count per pod and the ID of each pod.
|
||||
The get-hvglobalsession gets all local session by using view API service object(hvServer) of Connect-HVServer cmdlet.
|
||||
|
||||
.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
|
||||
View API service object of Connect-HVServer cmdlet.
|
||||
|
||||
.EXAMPLE
|
||||
Get-HVPodSession
|
||||
|
||||
.OUTPUTS
|
||||
Returns list of objects of type GlobalSessionPodSessionCounter
|
||||
Get-hvglobalsession
|
||||
Gets all global sessions
|
||||
|
||||
.NOTES
|
||||
Author : Rasmus Sjoerslev
|
||||
Author email : rasmus.sjorslev@vmware.com
|
||||
Author : Wouter Kursten.
|
||||
Author email : wouter@retouw.nl
|
||||
Version : 1.0
|
||||
|
||||
===Tested Against Environment====
|
||||
Horizon View Server Version : 7.0.2
|
||||
PowerCLI Version : PowerCLI 6.5
|
||||
Horizon View Server Version : 7.0.2, 7.1.0, 7.3.2
|
||||
PowerCLI Version : PowerCLI 6.5, PowerCLI 6.5.1
|
||||
PowerShell Version : 5.0
|
||||
#>
|
||||
|
||||
[CmdletBinding(
|
||||
SupportsShouldProcess = $true,
|
||||
ConfirmImpact = 'High'
|
||||
)]
|
||||
#>
|
||||
[CmdletBinding(
|
||||
SupportsShouldProcess = $true,
|
||||
ConfirmImpact = 'High'
|
||||
)]
|
||||
|
||||
param(
|
||||
param(
|
||||
[Parameter(Mandatory = $false)]
|
||||
$HvServer = $null
|
||||
)
|
||||
)
|
||||
|
||||
$services = Get-ViewAPIService -hvServer $hvServer
|
||||
if ($null -eq $services) {
|
||||
Write-Error "Could not retrieve ViewApi services from connection object"
|
||||
break
|
||||
}
|
||||
|
||||
$query_service_helper = New-Object VMware.Hv.GlobalSessionQueryServiceService
|
||||
$count_spec = New-Object VMware.Hv.GlobalSessionQueryServiceCountSpec
|
||||
$queryResults = @()
|
||||
|
||||
foreach ($pod in $services.Pod.Pod_List()) {
|
||||
$count_spec.Pod = $pod.Id
|
||||
$info = $query_service_helper.GlobalSessionQueryService_GetCountWithSpec($services,$count_spec)
|
||||
|
||||
foreach ($res in $info) {
|
||||
if ($pod.Id.Id -eq $res.Id.Id) {
|
||||
$queryResults += $res
|
||||
}
|
||||
}
|
||||
}
|
||||
return $queryResults
|
||||
$services = Get-ViewAPIService -HvServer $HvServer
|
||||
if ($null -eq $services) {
|
||||
Write-Error "Could not retrieve ViewApi services from connection object."
|
||||
break
|
||||
}
|
||||
|
||||
$query_service_helper = New-Object VMware.Hv.GlobalSessionQueryServiceService
|
||||
$query=new-object vmware.hv.GlobalSessionQueryServiceQuerySpec
|
||||
|
||||
$SessionList = @()
|
||||
$GetNext = $false
|
||||
foreach ($pod in $services.Pod.Pod_List()) {
|
||||
$query.pod=$pod.id
|
||||
$queryResults = $query_service_helper.GlobalSessionQueryService_QueryWithSpec($services, $query)
|
||||
do {
|
||||
if ($GetNext) { $queryResults = $query_service_helper.GlobalSessionQueryService_GetNext($services, $queryResults.id) }
|
||||
$SessionList += $queryResults.results
|
||||
$GetNext = $true
|
||||
} while ($queryResults.remainingCount -gt 0)
|
||||
$query_service_helper.GlobalSessionQueryService_Delete($services, $queryresults.id)
|
||||
|
||||
}
|
||||
return $sessionlist
|
||||
}
|
||||
|
||||
function Set-HVApplicationIcon {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
@@ -9857,4 +9858,136 @@ function Set-HVGlobalSettings {
|
||||
}
|
||||
}
|
||||
|
||||
Export-ModuleMember Add-HVDesktop,Add-HVRDSServer,Connect-HVEvent,Disconnect-HVEvent,Get-HVPoolSpec,Get-HVInternalName, Get-HVEvent,Get-HVFarm,Get-HVFarmSummary,Get-HVPool,Get-HVPoolSummary,Get-HVMachine,Get-HVMachineSummary,Get-HVQueryResult,Get-HVQueryFilter,New-HVFarm,New-HVPool,Remove-HVFarm,Remove-HVPool,Set-HVFarm,Set-HVPool,Start-HVFarm,Start-HVPool,New-HVEntitlement,Get-HVEntitlement,Remove-HVEntitlement, Set-HVMachine, New-HVGlobalEntitlement, Remove-HVGlobalEntitlement, Get-HVGlobalEntitlement, Get-HVPodSession, Set-HVApplicationIcon, Remove-HVApplicationIcon, Get-HVGlobalSettings, Set-HVGlobalSettings, Set-HVGlobalEntitlement, Get-HVResourceStructure
|
||||
function get-HVlocalsession {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Provides a list with all sessions on the local pod (works in CPA and non-CPA)
|
||||
|
||||
.DESCRIPTION
|
||||
The get-hvlocalsession gets all local session by using view API service object(hvServer) of Connect-HVServer cmdlet.
|
||||
|
||||
.PARAMETER HvServer
|
||||
View API service object of Connect-HVServer cmdlet.
|
||||
|
||||
.EXAMPLE
|
||||
Get-hvlocalsession
|
||||
Get all local sessions
|
||||
|
||||
.NOTES
|
||||
Author : Wouter Kursten.
|
||||
Author email : wouter@retouw.nl
|
||||
Version : 1.0
|
||||
|
||||
===Tested Against Environment====
|
||||
Horizon View Server Version : 7.0.2, 7.1.0, 7.3.2
|
||||
PowerCLI Version : PowerCLI 6.5, PowerCLI 6.5.1
|
||||
PowerShell Version : 5.0
|
||||
|
||||
#>
|
||||
[CmdletBinding(
|
||||
SupportsShouldProcess = $true,
|
||||
ConfirmImpact = 'High'
|
||||
)]
|
||||
|
||||
param(
|
||||
[Parameter(Mandatory = $false)]
|
||||
$HvServer = $null
|
||||
)
|
||||
|
||||
$services = Get-ViewAPIService -HvServer $HvServer
|
||||
if ($null -eq $services) {
|
||||
Write-Error "Could not retrieve ViewApi services from connection object."
|
||||
break
|
||||
}
|
||||
|
||||
$query_service_helper = New-Object VMware.Hv.QueryServiceService
|
||||
$query = New-Object VMware.Hv.QueryDefinition
|
||||
|
||||
$query.queryEntityType = 'SessionLocalSummaryView'
|
||||
$SessionList = @()
|
||||
$GetNext = $false
|
||||
$queryResults = $query_service_helper.QueryService_Create($services, $query)
|
||||
do {
|
||||
if ($GetNext) { $queryResults = $query_service_helper.QueryService_GetNext($services, $queryResults.id) }
|
||||
$SessionList += $queryResults.results
|
||||
$GetNext = $true
|
||||
}
|
||||
while ($queryResults.remainingCount -gt 0)
|
||||
$query_service_helper.QueryService_Delete($services, $queryResults.id)
|
||||
|
||||
|
||||
return $sessionlist
|
||||
[System.gc]::collect()
|
||||
}
|
||||
|
||||
function Reset-HVMachine {
|
||||
<#
|
||||
.Synopsis
|
||||
Resets Horizon View desktops.
|
||||
|
||||
.DESCRIPTION
|
||||
Queries and resets virtual machines, the machines list would be determined
|
||||
based on queryable fields machineName. Use an asterisk (*) as wildcard. If the result has multiple machines all will be reset.
|
||||
Please note that on an Instant Clone Pool this will do the same as a recover of the machine.
|
||||
|
||||
.PARAMETER MachineName
|
||||
The name of the Machine(s) to query for.
|
||||
This is a required value.
|
||||
|
||||
.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
|
||||
|
||||
.EXAMPLE
|
||||
reset-HVMachine -MachineName 'PowerCLIVM'
|
||||
Queries VM(s) with given parameter machineName
|
||||
|
||||
|
||||
.EXAMPLE
|
||||
reset-HVMachine -MachineName 'PowerCLIVM*'
|
||||
Queries VM(s) with given parameter machinename with wildcard character *
|
||||
|
||||
.NOTES
|
||||
Author : Wouter Kursten
|
||||
Author email : wouter@retouw.nl
|
||||
Version : 1.0
|
||||
|
||||
===Tested Against Environment====
|
||||
Horizon View Server Version : 7.3.2
|
||||
PowerCLI Version : PowerCLI 6.5, PowerCLI 6.5.1
|
||||
PowerShell Version : 5.0
|
||||
#>
|
||||
|
||||
[CmdletBinding(
|
||||
SupportsShouldProcess = $true,
|
||||
ConfirmImpact = 'High'
|
||||
)]
|
||||
|
||||
param(
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string]
|
||||
$MachineName,
|
||||
|
||||
[Parameter(Mandatory = $false)]
|
||||
$HvServer = $null
|
||||
)
|
||||
|
||||
|
||||
$services = Get-ViewAPIService -hvServer $hvServer
|
||||
if ($null -eq $services) {
|
||||
Write-Error "Could not retrieve ViewApi services from connection object"
|
||||
break
|
||||
}
|
||||
|
||||
$machineList = Find-HVMachine -Param $PSBoundParameters
|
||||
if (!$machineList) {
|
||||
Write-Host "Reset-HVMachine: No Virtual Machine(s) Found with given search parameters"
|
||||
break
|
||||
}
|
||||
foreach ($machine in $machinelist){
|
||||
$services.machine.Machine_ResetMachines($machine.id)
|
||||
}
|
||||
}
|
||||
|
||||
Export-ModuleMember Add-HVDesktop,Add-HVRDSServer,Connect-HVEvent,Disconnect-HVEvent,Get-HVPoolSpec,Get-HVInternalName, Get-HVEvent,Get-HVFarm,Get-HVFarmSummary,Get-HVPool,Get-HVPoolSummary,Get-HVMachine,Get-HVMachineSummary,Get-HVQueryResult,Get-HVQueryFilter,New-HVFarm,New-HVPool,Remove-HVFarm,Remove-HVPool,Set-HVFarm,Set-HVPool,Start-HVFarm,Start-HVPool,New-HVEntitlement,Get-HVEntitlement,Remove-HVEntitlement, Set-HVMachine, New-HVGlobalEntitlement, Remove-HVGlobalEntitlement, Get-HVGlobalEntitlement, Set-HVApplicationIcon, Remove-HVApplicationIcon, Get-HVGlobalSettings, Set-HVGlobalSettings, Set-HVGlobalEntitlement, Get-HVResourceStructure, Get-hvlocalsession, Get-HVGlobalSession, Reset-HVMachine
|
||||
|
||||
Reference in New Issue
Block a user