9 Replies Latest reply on Feb 27, 2020 6:51 AM by aWanderer

    Setup/Use of PowerCLI

    aWanderer Lurker

      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. Re: Setup/Use of PowerCLI
          RoderikdeBlock Hot Shot

          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 · GitHub

          1 person found this helpful
          • 2. Re: Setup/Use of PowerCLI
            Mickeybyte Hot Shot

            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.

            2 people found this helpful
            • 3. Re: Setup/Use of PowerCLI
              aWanderer Lurker

              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

              • 4. Re: Setup/Use of PowerCLI
                aWanderer Lurker

                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

                • 5. Re: Setup/Use of PowerCLI
                  Mickeybyte Hot Shot

                  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 )

                   

                  Regards.

                  • 6. Re: Setup/Use of PowerCLI
                    RoderikdeBlock Hot Shot

                    Try this:

                     

                    Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false

                    • 7. Re: Setup/Use of PowerCLI
                      aWanderer Lurker

                      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

                       

                      • 8. Re: Setup/Use of PowerCLI
                        aWanderer Lurker

                        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.

                        • 9. Re: Setup/Use of PowerCLI
                          aWanderer Lurker

                          Thanks all for the help. Much appreciated.