vSphere PowerCLI : Part - II

image Now that you guys have installed PowerCLI and you have got an idea how to start use PowerCLI, today we would look at some PowerCLI commands which would be use full in day-to-day administration.

To connect to your ESX/I or VC system use the below command:
PS> Connect-VIServer <IP for ESX/I or VC> or <DNSNAME for ESX/I or VC>
EG --> Connect-VIServer
EG --> Connect-VIServer esx01
EG --> Connect-VIServer VC01

Once this is enter, a window will pop up for login credentials. If you are connecting to your ESX or ESXi system authenticate with root user. If you are connecting to your VC authenticate with the user which has admin access to the VC.

Now that you are able to connect the your host / VC using PowerCLI, lets have a look at some useful commands for the ESX adminstration..

To list all the VMware Infrastructure Servers (VMHost) on the connected VI Server

Get all Hosts member of a Cluster
Get-Cluster Cluster01 | Get-VmHost

To add a new VMHost to inventory (requires connection to vCenter)
Add-VMHost ESX01 -Location (Get-Datacenter Main) -User root -Password MyPass

To remove a VMHost
Get-VMHost ESX01 | Remove-VmHost

To move a VMHost
Move-VMHost (Get-VMHost ESX01 ) -Destination (Get-Datacenter MyDatacenter)

To change the state of a VMHost
# Disconnect Host
Set-VmHost -VmHost ESX01 -State ”Disconnected“
# Enter Host in maintenance mode
Set-VmHost -VmHost (Get-VmHost -Name ”ESX01”) -State ”Maintenance“
#Connect Host or Exit Maintenance
Set-VmHost -VmHost (Get-VmHost -Name ”ESX01”) -State ”Connected“

ESX Host Accounts (requires direct ESX Host connection)
Get-VMHostAccount -user
New-VMHostAccount -ID user -Password password -UserAccount
New-VMHostAccount -Id normalusers -GroupAccount -AssignUsers user
Get-VMHostAccount - Group -ID user | Remove-VMHostAccount -Confirm

Service Configuration (requires direct ESX connection)
Get-VMHostService -Refresh
Get-VmHostService -VMHost | ?{$_.key -eq ”vmware-vpxa“} |Restart-VMHostService

NTP Server settings
Get-VMHostNtpServer ESX01
Add-VmHostNtpServer -NtpServer ”

“ -VMHost (Get-VMHost ESX01 )

Previous                                                                                                                     Continued....


  1. Thanks to published this....

    If it possible to get the ESX host NIC information through vSphere PowerCLi.........

  2. I have a Windows workstation with vSphere client on it. I have a ps1 script (on my local Win box) to set some networking paramaters on an ESX server. I have 3 versions of the script, and 3 ESX servers. How do I run script 1 on ESX server 1, script 2 on ESX server 2 and script 3 on ESX server 3?

    Thanks much,


Post a Comment

Popular posts from this blog

VMWare Interview Questions & Tips

Windows: 2012 Server: Restoration of server from ransomware brute force attack – Real time experience

Windows and VMware : System Admin Responsibilities