VMware Horizon Community
aWanderer
Enthusiast
Enthusiast
Jump to solution

Setup/Use of PowerCLI

Hello,

Looking for some instructions on the use of PowerShell and Horizon 7.6.  I have tried following instructions at VMware and elsewhere but it only leads to errors.  None of the scripts run.  Here is what I am trying to do or have done:

- My workstation is Windows 10

As admin, launched PowerShell and executed the following commands:

- Install-Module -Name VMware.PowerCLI -RequiredVersion 10.1.1.8827524

- Install-Module -Name Vmware.PowerCLI

Now I want to simply query the Horizon environment for Pool info, VM info, etc.

Should I be doing this ON the Connection server rather than on my Windows 10 Desktop?

Any help would be greatly appreciated.

1 Solution

Accepted Solutions
aWanderer
Enthusiast
Enthusiast
Jump to solution

I think I figured it out...

  1. Install-Module -Name VMware.PowerCLI -RequiredVersion 10.1.1.8827524
  2. Install-Module -Name Vmware.PowerCLI
  3. I downloaded GitHub - vmware/PowerCLI-Example-Scripts
  4. Extracted it
  5. Copied the VMware.Hv.Helper folder to my Modules path

Load the module and queried the VM's like this:

Import-Module VMware.VimAutomation.HorizonView

Import-Module VMware.VimAutomation.cis.Core

Get-Module -ListAvailable 'VMware.Hv.Helper' | Import-Module

Get-Module -ListAvailable VMware* | Import-Module

$CS = Connect-HVServer -Server "YourServerName"

Get-HVMachineSummary | Out-GridView

Get-HVMachineSummary -State AGENT_UNREACHABLE | Out-GridView

Disconnect-HVServer -Server "YourServerName" -Confirm:$false

Seemed to work. I'm just winging it here.

View solution in original post

9 Replies
RoderikdeBlock
Enthusiast
Enthusiast
Jump to solution

Next step is to run the following.

  1. Import HorizonView module by running: Import-Module VMware.VimAutomation.HorizonView.
  2. Import "VMware.Hv.Helper" module by running: Import-Module -Name "location of this module" or Get-Module -ListAvailable 'VMware.Hv.Helper' | Import-Module.
  3. Get-Command -Module "This module Name" to list all available functions or Get-Command -Module 'VMware.Hv.Helper'

You can check the following on github. (Lots of examples scripts)

PowerCLI-Example-Scripts/Modules/VMware.Hv.Helper at master · vmware/PowerCLI-Example-Scripts · GitH...

Roderik de Block


Blog: https://roderikdeblock.com
Mickeybyte2
Hot Shot
Hot Shot
Jump to solution

Hi aWanderer,

You can run the scripts from your workstation where you installed the powershell module.

After installing the module, you need to import the desired modules before you can use them. Then you use the connect command to connect to your connection server and retrieve the info you need.

I've created a blog post about this recently, you can check it out here: https://itpro.peene.be/vmware-horizon-powerschell-scripting-viewapi/

I use it for writing monitoring scripts for PRTG, but you can use the information on my blog for any other scripting needs.

Hope this helps you.

Regards.

Regards, Michiel.
aWanderer
Enthusiast
Enthusiast
Jump to solution

Thank you very much for the help all.

In the blog, it says

"Import-Module VMware.VimAutomation.Core"

It errors but I do see on my system VMware.VimAutomation.cis.Core so I tried Import-Module VMware.VimAutomation.cis.Core and it worked.

Is this the correct import?

As it is, I now have the following and it seems to load fine:

Import-Module VMware.VimAutomation.cis.Core

Import-Module VMware.VimAutomation.HorizonView

Get-Module -ListAvailable 'VMware.Hv.Helper' | Import-Module

The Set-PowerCLIConfiguration command throws an error:

Set-PowerCLIConfiguration -Scope Allusers -ParticipateInCEIP $false

Set-PowerCLIConfiguration : The term 'Set-PowerCLIConfiguration' is not recognized as the name of a cmdlet, function, script file, or operable program.

Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

At line:1 char:1

+ Set-PowerCLIConfiguration -Scope Allusers -ParticipateInCEIP $false

+ ~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : ObjectNotFound: (Set-PowerCLIConfiguration:String) [], CommandNotFoundException

    + FullyQualifiedErrorId : CommandNotFoundException

When all is done, I want to be able to do something like this:

Get-PoolEntitlement

Reply
0 Kudos
aWanderer
Enthusiast
Enthusiast
Jump to solution

When I try to connect to the Connection server, I receive this error:

     Connect-HVServer : Could not establish trust relationship for the SSL/TLS secure channel with authority

I am using this command to connect:

Connect-HVServer -Server "theServerName"

Oops... using the FQDN worked

Mickeybyte2
Hot Shot
Hot Shot
Jump to solution

Hi aWanderer

The set-PowerCLICOnfiguration is only needed to disable the warning message about data sharing with VMWare when you execute certain powerCLI commands. No need to worry about it.

What's the error message you get when you import the vmware.vimautomation.core module? Did you install both modules?

Install-Module -Name VMware.VimAutomation.Core
Install-Module -Name VMware.VimAutomation.HorizonView

As far as I know there's no get-poolentitlement command available. You'll have to search around to see how to get the entitlements using PowerCLI (Google can help here Smiley Wink)

Regards.

Regards, Michiel.
Reply
0 Kudos
RoderikdeBlock
Enthusiast
Enthusiast
Jump to solution

Try this:

Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false

Roderik de Block


Blog: https://roderikdeblock.com
aWanderer
Enthusiast
Enthusiast
Jump to solution

Just returns

     Set-PowerCLIConfiguration : The term 'Set-PowerCLIConfiguration' is not recognized

That's ok. We can forget about that. I'm trying to figure out how to get a list of VM's, Pools, etc.  Trying to work through learning how to query things.  I can't find any examples that work for me.

I am connected though. So far, I have this

#Install-Module -Name VMware.VimAutomation.Core

#Install-Module -Name VMware.VimAutomation.HorizonView

Import-Module VMware.VimAutomation.cis.Core

Import-Module VMware.VimAutomation.HorizonView

Get-Module -ListAvailable 'VMware.Hv.Helper' | Import-Module

$CS = Connect-HVServer -Server "ServerName"

$Services1 = $Global:DefaultHVServers.ExtensionData

Reply
0 Kudos
aWanderer
Enthusiast
Enthusiast
Jump to solution

I think I figured it out...

  1. Install-Module -Name VMware.PowerCLI -RequiredVersion 10.1.1.8827524
  2. Install-Module -Name Vmware.PowerCLI
  3. I downloaded GitHub - vmware/PowerCLI-Example-Scripts
  4. Extracted it
  5. Copied the VMware.Hv.Helper folder to my Modules path

Load the module and queried the VM's like this:

Import-Module VMware.VimAutomation.HorizonView

Import-Module VMware.VimAutomation.cis.Core

Get-Module -ListAvailable 'VMware.Hv.Helper' | Import-Module

Get-Module -ListAvailable VMware* | Import-Module

$CS = Connect-HVServer -Server "YourServerName"

Get-HVMachineSummary | Out-GridView

Get-HVMachineSummary -State AGENT_UNREACHABLE | Out-GridView

Disconnect-HVServer -Server "YourServerName" -Confirm:$false

Seemed to work. I'm just winging it here.

aWanderer
Enthusiast
Enthusiast
Jump to solution

Thanks all for the help. Much appreciated.

Reply
0 Kudos