#VMware #Horizon #VMware #PowerCLI

VMware PowerCLI 13. Horizon PowerCLI module, VDI-. , .

PowerCLI Horizon View API, . , VDI-c , GitHub.

View API, Horizon RESTful API, VMware Horizon Server API. Connection Server ( ).

, :

Horizon PowerCLI :

  • VMware PowerCLI
  • advanced functions

1. VMware PowerCLI

. Windows PowerShell Admin console :

Install-Module VMware.PowerCLI

:

Set-ExecutionPolicy RemoteSigned

2. Advanced Functions

GitHub Download ZIP:

zip- Hv.Helper modules . , $env:PSModulePath. :

  • User specific:%UserProfile%\Documents\WindowsPowerShell\Modules
  • System wide:C:\Program Files\WindowsPowerShell\Modules

, . PowerShell :


dir ‘C:\Program
Files\WindowsPowerShell\Modules\VMware.HvHelper\’ |
Unblock-File


3.

2 :


. , :

Get-Module -ListAvailable VMware* | Import-Module

Horizon, :

Import-Module VMware.VimAutomation.HorizonView

Import-Module VMware.VimAutomation.Core

Horizon Connection Server View API, :

Connect-HVServer -server s1-hcs1.mydomain.com

:

Connect-HVServer -server horizon1.mydomain.com -user demoadmin -password mypassword -domain mydomain

DefaultHVServers, Horizon Connection Servers. $Global:DefaultHVServers.

ExtensionData. $Services :

$services=$Global:DefaultHVServers.ExtensionData

$services

View API, . ExtensionData View API.

. Horizon Connection Servers (pod). View API ConnectionServer ConnectionServer_List $hvServers1.

$hvservers = $services.ConnectionServer.ConnectionServer_List()

$hvservers.General

, Horizon Agent . , , , .

, , , :

$DisconnectedVMs = Get-HVMachineSummary -State DISCONNECTED

$DisconnectedVMs | Out-GridView

.

, :

  • PROVISIONING_ERROR
  • ERROR
  • AGENT_UNREACHABLE
  • AGENT_ERR_STARTUP_IN_PROGRESS
  • AGENT_ERR_DISABLED
  • AGENT_ERR_INVALID_IP
  • AGENT_ERR_NEED_REBOOT
  • AGENT_ERR_PROTOCOL_FAILURE
  • AGENT_ERR_DOMAIN_FAILURE
  • AGENT_CONFIG_ERROR
  • UNKNOWN

, , , :

$ProblemVMs = Get-HVMachineSummary -State AGENT_UNREACHABLE

, , Horizon Agent . – , , ( , AGENT_ERR_NEED_REBOOT).

. , , Connection Server, , . , Connect-HVServer Connect-VIServer – .

-WhatIf Restart-VMGuest – .


#################################################################### 

# Get List of Desktops that have Horizon Agent in problem states. 

# Reboot the OS of each of these. 

#################################################################### 

#region variables 

################################################################### 

# Variables 

################################################################### 

$cs="s1-hcs1.mydomain.com" #Horizon Connection Server 

$csUser="administrator" #Connection Server user 

$csPassword = 'mypassword' #Connection Server user password 

$csDomain = 'mydomain' #Connection Server domain 

$vc="vcenter1.mydomain.com" #vCenter Server 

$vcUser="administrator@vsphere.local" #vCenter Server user 

$vcPassword = 'mypassword' #vCenter Server password 

$baseStates = @('PROVISIONING_ERROR',  

                'ERROR',  

                'AGENT_UNREACHABLE',  

                'AGENT_ERR_STARTUP_IN_PROGRESS', 

                'AGENT_ERR_DISABLED',  

                'AGENT_ERR_INVALID_IP',  

                'AGENT_ERR_NEED_REBOOT',  

                'AGENT_ERR_PROTOCOL_FAILURE',  

                'AGENT_ERR_DOMAIN_FAILURE',  

                'AGENT_CONFIG_ERROR',  

                         'UNKNOWN') 

#endregion variables 

#region initialize 

################################################################### 

# Initialize 

################################################################### 

# --- Import the PowerCLI Modules required --- 

Import-Module VMware.VimAutomation.HorizonView 

Import-Module VMware.VimAutomation.Core 

Set-PowerCLIConfiguration -InvalidCertificateAction Prompt 

# --- Connect to Horizon Connection Server API Service --- 

$hvServer = Connect-HVServer -Server $cs -User $csUser -Password $csPassword -Domain $csDomain 

# --- Get Services for interacting with the View API Service --- 

$services= $hvServer.ExtensionData 

# --- Connect to the vCenter Server --- 

Connect-VIServer -Server $vc -User $vcUser -Password $vcPassword 

#endregion initialize 

#region main 

################################################################### 

# Main 

################################################################### 

Write-Output "" 

if ($services) { 

foreach ($baseState in $baseStates) { 

# --- Get a list of VMs in this state --- 

Write-Host ("Get VMs with baseState: " + $baseState) -ForegroundColor Yellow 

$ProblemVMs = Get-HVMachineSummary -State $baseState 

foreach ($ProblemVM in $ProblemVMs) { 

$VM = Get-VM -Name $ProblemVM.Base.Name 

# --- Reboot each of the Problem VMs --- 

Restart-VMGuest -VM $VM 

# Add -WhatIf to see what would happen without actually carrying out the action. 

} 

} 

Write-Output "", "Disconnect from Connection Server." 

Disconnect-HVServer -Server $cs 

} else { 

Write-Output "", "Failed to login into Connection Server." 

pause 

} 

# --- Disconnect from the vCenter Server --- 

Write-Output "", "Disconnect from vCenter Server." 

Disconnect-VIServer -Server $vc 

#endregion main



Share:

administrator

ahmedaljanahy Creative Designer @al.janahy Founder of @inkhost I hope to stay passionate in what I doing

Leave a Reply

Your email address will not be published. Required fields are marked *