PowerCLI script examples

Here are some of the examples of PowerCLI scripts used to perform some tasks in the vSphere environment:

  • Moving VM: If you want to move all VMs to another host, use the following script:
Get-VMHost esxi01 | Get-VM | Move-VM -Destination (Get-VMHost esxi02)

To move a single VM to a different host, use the following script:

Move-VM -VM VM_name -Destination esxi01
A PowerCLI cmdlet can be used to move a virtual machine to a different host
  • VM info: Previously, we used the command Get-VM to retrieve a list of running VMs in the vCenter Server instance. You also have the option of exporting the list of VMs in a .csv file, including some properties you want to specify:
Get-VM | Select-Object Name,NumCPU,MemoryMB,PowerState,Host | Export-CSV VMinfo.csv -NoTypeInformation

To know on which host a specific virtual machine runs, use the following script:

Get-VMHost -VM (Get-VM -Name VM_name)
 PowerCLI cmdlet can also be used to know which host a specific VM runs on 
  • Configuring NTP: We discussed the importance of having the hosts time-synced to avoid authentication issues. The following cmdlet configures the NTP server for the specific host:
Get-VMHost <esxi01> | Add-VMHostNtpServer -NtpServer <NTPServer>
NTP server configured for a specific host using PowerCLI
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.12.166.76