VMware Cloud Community
ranis5208
Contributor
Contributor

Can PowerCLI work on windows desktop and query directly to ESXI without having the Vsphere and Vcenter installed on desktop?

Any prompt answer will be appreciated!!VMware PowerCLI

0 Kudos
17 Replies
LucD
Leadership
Leadership

I assume you want to know if you can connect to an ESXi node directly with PowerCLI?

Well yes, you can.

In fact with Connect-VIServer you can connect to any vSphere server, beit a vCenter or an ESXi node.

You do of course need the credentials for that ESXi node.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
ranis5208
Contributor
Contributor

I'm getting below error message while connecting to ESXI via root credentials....

PS C:\Users\S> Connect-VIServer 10.214.60.144

Connect-VIServer : 6/29/2018 5:29:31 PM Connect-VIServer                Error: Invalid server certificate. Use

Set-PowerCLIConfiguration to set the value for the InvalidCertificateAction option to Prompt if you'd like to connect

once or to add a permanent exception for this server.

Additional Information: Could not establish trust relationship for the SSL/TLS secure channel with authority

'10.214.60.144'.

At line:1 char:1

+ Connect-VIServer 10.214.60.144

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

    + CategoryInfo          : SecurityError: (:) [Connect-VIServer], ViSecurityNegotiationException

    + FullyQualifiedErrorId : Client20_ConnectivityServiceImpl_Reconnect_CertificateError,VMware.VimAutomation.ViCore.

   Cmdlets.Commands.ConnectVIServer

0 Kudos
LucD
Leadership
Leadership

Did you configure PowerCLI to ignore invalid certificates?

Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
ranis5208
Contributor
Contributor

Yes it worked.. Thank You!!

Could you please let me know is there any option through which we can query host without using root credentials?

0 Kudos
LucD
Leadership
Leadership

You are connecting to the ESXi node I guess then?

You can also connect to a vCenter, and then access all ESXi nodes that are known in that vCenter.

Note that some functionality requires a connection to the ESXi node.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
ranis5208
Contributor
Contributor

Yeah, I'm working with lab EXSi host.

We need to have below requirement to be fulfilled by using POWERCLI.

-PING status whether the host is up or not

-To check status of important services of ESXIs

-Utilization of CPU, Memory, IOPS, Counters(Disk Queue Length)

-Disk free space(Free space of all the logical Drives)

Could you please help me getting above requirement scripts.

0 Kudos
LucD
Leadership
Leadership

And would you like rice or fries with that?

Seriously, what do you already have?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
ranis5208
Contributor
Contributor

Actually i'm new to PowerCLI.

If you could help .. it will be very helpful.

0 Kudos
LucD
Leadership
Leadership

Sure, in fact most of the points you raise are simple cmdlets.

  • a ping can be done with the Test-NetConnection cmdlet. Since the cmdlet has many variations, you will have to decide how and what you want to test with the 'ping'
  • a number of ESXi nodes services can be queried with the Get-VMHostService cmdlet
  • performance data can be retrieved with the Get-Stat cmdlet. Not all the metrics you list are available as-is, some will require additional calculations. The easiest way to select yoru starting metrics is to look at the Performance tab in the Web Client. In there you can find the names of the metrics.
  • Not sure what you mean with logical drive, is that a Datastore or a vDisk connected to a VM?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
ranis5208
Contributor
Contributor

Thank you so much for sharing below..

These worked on Wednesday when I restarted my pc don't know why it's not working and giving below error message.. Could you please take a look and suggest what to do?

PS C:\Users\S> Connect-VIServer '10.21.60.1' -user root -password W@123

Connect-VIServer : Could not load file or assembly 'VMware.Vim, Version=6.7.0.1174, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file

specified.

At line:1 char:1

+ Connect-VIServer '10.21.60.1' -user root -password W@123

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

    + CategoryInfo          : NotSpecified: (:) [Connect-VIServer], FileNotFoundException

    + FullyQualifiedErrorId : System.IO.FileNotFoundException,VMware.VimAutomation.ViCore.Cmdlets.Commands.ConnectVIServer

0 Kudos
LucD
Leadership
Leadership

Looks like your PowerCLI installation might be corrupted.
Do you perhaps still have part of an MSI-based install on the system, mixed with an install from the PowerShell Gallery?

What does this return?

Get-Module -Name VMware* -ListAvailable

Get-PSSnapin -Registered


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
ranis5208
Contributor
Contributor

On powerCLI and powerShell returning the same as below

PS C:\Users\S1007339> Get-Module -Name VMware* -ListAvailable

 

    Directory: C:\Users\S\Documents\WindowsPowerShell\Modules

 

ModuleType Version    Name                                ExportedCommands                                                          

---------- -------    ----                                ----------------                                                          

Script     6.7.0.8... VMware.DeployAutomation             {Add-DeployRule, Add-ProxyServer, Add-ScriptBundle, Copy-DeployRule...}   

Script     6.7.0.8... VMware.ImageBuilder                 {Add-EsxSoftwareDepot, Add-EsxSoftwarePackage, Compare-EsxImageProfile, ...

Manifest   10.1.1.... VMware.PowerCLI                                                                                               

Script     6.7.0.8... VMware.Vim                                                                                                    

Script     10.1.0.... VMware.VimAutomation.Cis.Core       {Connect-CisServer, Disconnect-CisServer, Get-CisService}                 

Script     10.0.0.... VMware.VimAutomation.Cloud          {Add-CIDatastore, Connect-CIServer, Disconnect-CIServer, Get-Catalog...}  

Script     10.1.0.... VMware.VimAutomation.Common                                                                                   

Script     10.1.0.... VMware.VimAutomation.Core           {Add-PassthroughDevice, Add-VirtualSwitchPhysicalNetworkAdapter, Add-VMH...

Script     6.5.4.7... VMware.VimAutomation.HA             Get-DrmInfo                                                               

Script     7.5.0.8... VMware.VimAutomation.HorizonView    {Connect-HVServer, Disconnect-HVServer}                                   

Script     10.0.0.... VMware.VimAutomation.License        Get-LicenseDataManager                                                    

Script     10.1.0.... VMware.VimAutomation.Nsxt           {Connect-NsxtServer, Disconnect-NsxtServer, Get-NsxtService}              

Script     10.0.0.... VMware.VimAutomation.PCloud         {Connect-PIServer, Disconnect-PIServer, Get-PIComputeInstance, Get-PIDat...

Script     10.1.0.... VMware.VimAutomation.Sdk            {Get-PSVersion, Get-InstallPath}                                          

Script     10.0.0.... VMware.VimAutomation.Srm            {Connect-SrmServer, Disconnect-SrmServer}                                 

Script     10.1.0.... VMware.VimAutomation.Storage        {Add-KeyManagementServer, Copy-VDisk, Export-SpbmStoragePolicy, Get-KeyM...

Script     1.2.0.0    VMware.VimAutomation.StorageUtility Update-VmfsDatastore                                                      

Script     10.1.0.... VMware.VimAutomation.Vds            {Add-VDSwitchPhysicalNetworkAdapter, Add-VDSwitchVMHost, Export-VDPortGr...

Script     10.0.0.... VMware.VimAutomation.Vmc            {Connect-Vmc, Disconnect-Vmc, Get-VmcService, Connect-VmcServer...}       

Script     10.0.0.... VMware.VimAutomation.vROps          {Connect-OMServer, Disconnect-OMServer, Get-OMAlert, Get-OMAlertDefiniti...

Script     6.5.1.7... VMware.VumAutomation                {Add-EntityBaseline, Copy-Patch, Get-Baseline, Get-Compliance...}         

PS C:\Users\S> Get-PSSnapin -Registered

Name        : VMware.DeployAutomation

PSVersion   : 2.0

Description : Cmdlets for Rule-Based-Deployment

Name        : VMware.ImageBuilder

PSVersion   : 2.0

Description : This Windows PowerShell snap-in contains VMware ESXi Image Builder cmdlets used to generate custom images.

Name        : VMware.VimAutomation.Core

PSVersion   : 2.0

Description : This Windows PowerShell snap-in contains Windows PowerShell cmdlets for managing vSphere.

Name        : VMware.VimAutomation.License

PSVersion   : 2.0

Description : This Windows Powershell snap-in contains cmdlets for managing License components.

0 Kudos
LucD
Leadership
Leadership

That's what I was afraid off, you have 2 versions of PowerCLI intermixed.

You should uninstall both versions, and reinstall the latest from the PowerShell Gallery.

  1. Uninstall the entry that you see in Program and Features in the Control Panel
  2. Remove the complete folder (if still there) C:\Program Files (x86)\VMware\Infrastructure\
  3. Remove all VMware modules in any of the folders that are listed in $env:PSModulePath
  4. To be safe, restart your station
  5. Install the latest VMware PowerCLI with Install-Module

You will find most of these instructions as well in

Welcome PowerCLI to the PowerShell Gallery - Install Process Updates

PowerCLI Offline Installation Walkthrough


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
ranis5208
Contributor
Contributor

  • It worked.. I did the same way as you told..Thank you so much..
  • One more query I have.. when i'm exporting the report getting duplicate entries.. Is there any way we can avoid it?
0 Kudos
LucD
Leadership
Leadership

What duplicate entries do you get?

How are you creating the report? I would need to see the code.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
ranis5208
Contributor
Contributor

Thank you so much for all your help!!

Is there any option so that we login to ESXI and check the status of VC(If VCenter server is shutdown stage)??

0 Kudos
LucD
Leadership
Leadership

If you know on which ESXi node the vCenter is running, you can do a Connect-VIServer to that ESXi node.
And then with Get-VM query the state of the vCenter VM


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos