PowerCLI cmdlets


Connecting to a Server
To run specific vSphere PowerCLI cmdlets and perform administration or monitoring tasks, first establish a
connection to an ESX or a vCenter Server.
In the vSphere PowerCLI console window, type the following cmdlet:
Connect-VIServer -Server

To manage virtual machines
1 After establishing a connection to a server, list all virtual machines on the target system:
Get-VM | sort name
2 Save the name and the power state properties of the virtual machines in the myPool resource pool into a
file named myVMProperties.txt:
$pool = Get-ResourcePool myPool
Get-VM -Location $pool | Select-Object Name, PowerState > myVMProperties.txt
3 Start the MyVM virtual machine:
Get-VM "myVM" | Start-VM
4 Retrieve information of the guest OS of the myVM virtual machine:
Get-VMGuest myVM | fc
5 Shutdown the OS of the myVM virtual machine:
Shutdown-VMGuest "myVM"
6 Power off the myVM virtual machine:
Stop-VM "myVM"
7 Move the virtual machine myVM from the ABC host to the XYZ host:
Get-VM -Name “myVM” -Location (Get-VMHost ‘ABC’) | Move-VM –Destination (Get-VMHost ‘XYZ’)

To manage virtual machine hosts
1 List all hosts on the target VMware vSphere server you have established a connection with:
Get-VMHost
2 Add a standalone virtual machine host to the vCenter Server:
Add-VMHost -Name myHost -Location (Get-Datacenter Main) -User root -Password pass
3 Activate maintenance mode for the myHost virtual machine host:
Get-VMHost myHost | Set-VMHost -State maintenance
4 Remove the myHost virtual machine host from maintenance mode:
Get-VMHost myHost | Set-VMhost -State connected
5 Shut down the myHost virtual machine host
$host = Get-VMHost myHost
$hv = Get-View $h.ID
$hv.ShutdownHost_Task($true)
6 Remove the myHost virtual machine host without confirmation:
Remove-VMHost $host -Confirm:$false


To manage cluster

Get-cluster | sort-object "Name"

Comments