facebooktwitteryoutube
Home About VCP Virtual Home Lab VCP6 Study Guide VCAP6-DCV Deploy Study guide VCAP6 – DCV Design Collection
in PowerCLI - 16 Jun, 2016
by mordi - no comments
VCAP-DCV Deploy Objective 5.1

We are now in the fifth section of the blueprint ,In this section we are going to cover how to Execute VMware Cmdlets and Customize Scripts Using PowerCLI

Here are the objective from the blueprint :

  • Install and configure vSphere PowerCLI
  • Use basic and advanced PowerCLI Cmdlets to manage a vSphere deployment
  • Analyze a sample script, then modify the script to perform a given action
  • Create a report from a PowerCLI script
  • Use PowerCLI to configure and administer Auto Deploy (including Image Builder)

Lab Setup:

Using VMware workstation:

  • Microsoft Servers 2012R2 for Services (DNS , DHCP, etc…)
  • installed esx0
  • Installed VCSA
  • Management workstation (Windows OS)

 Documents used:

  • VMware vSphere PowerCLI User’s Guide
  • VMware vSphere PowerCLI Cmdlets Reference

 

Install and configure vSphere PowerCLI:

Before we can install PowerCLI we need to download the latest version from VMware website : https://my.vmware.com/group/vmware/get-download?downloadGroup=PCLI630R1

At the time of writting this post I am downloading version 6.3 Release 1

PowerCLI1

The installation is very basic (just click Next next….) and you done and you going to see two new icons on your desktop , click on the “VMware vSphere PowerCLI” and now we can start scripting

PowerCLI2

For configuration We need to change the execution policy of Windows PowersShell to RemoteSigned, so we can run scripts.

Run the following command: Set-ExecutionPolicy RemoteSigned . click Y to enable the remore execution policy 

Use basic and advanced PowerCLI Cmdlets to manage a vSphere deployment:

Note this is just BASIC PowerCLI commands , People wrote a lot of good books about it and it will take more than a post to learn it.

PowerCLI3

I am not going to cover all the commands in the CLI , but will discuss the basics:

To see a full list of all VMware related Cmdlets run the following command :  Get-Command -Module vmware* |more

POwerCLIVM5

Connecting to a vCenter Server System:

Connecting to vCenter  – Connect-VIServer -Server SEVER NAME/IP -Protocol https -User xxx -Password xxxthe output show that we are connected

PowerCLI2

Some command to managed VM’s:

  • Get-VM – List all VM’s
  • Start-VM – starting the VM
  • Get-VMGuest – Get info about the OS
  • Stop-VM – Power off the VM

POwerCLIVM1

Some command to managed Hosts:

  • Get -VmHost – list all hosts
  • Put a host in a variable – $vmhost=get-vmhost -name esx1.vsphere6.local
  • Put host in maintenance mode – Set-VMHost -VMHost $vmhost -State “Maintenance” -RunAsync

POwerCLIVM2

Some Networking commands:

  • Get-VMhostNetwork – shows network info for the host
  • You can add -Property like physicalnic and get the list of vnics
  • Get-VMhostNetworkAdapter gives more detailed info about the vmnics
  • and you can use VMhostNetworkAdapter with -Vmkernel to list your VMkernels

POwerCLIVM3

Some Storage commands:

  • Get-VMHostHBA -Type iSCSI – list iSCSI HBA’s
  • Get-VMHostStorage $vmhost -RescanAllHba – rescan all HBA

POwerCLIVM4

Analyze a sample script, then modify the script to perform a given action and Create a report from a PowerCLI script:

I combine these two task into one so we will create a sample script,have the script perform action and create a report

The script objective will be :

  • Start powered off VM’s in the cluster
  • Take a snapshot off all VM’s
  • Create a report about snapshot history for the vm;s

 

  1. Connect-VIServer -Server 192.168.1.34 -Protocol https -User administrator@vsphere.local -Password $VMware123
  2. $offlineVMs = Get-VM | Where-Object {$_.PowerState -eq “PoweredOff”}
  3. $offlineVMs |start-vm -Runasync -Confirm:$false | Out-Null
  4. Get-vm |New-Snapshot -name snap1
  5. get-vm |Get-Snapshot|select vm ,Name , Created

 

POwerCLIVM6

Use PowerCLI to configure and administer Auto Deploy (including Image Builder):

Already have a post about this here is the link:

VCP6-DCV blueprint section 8.1:Deploy ESXi Hosts Using Autodeploy

 

 

 

Thanks for reading

Mordi.

 

Leave a Reply