automation using power cli
TRANSCRIPT
Automa'on Using PowerCLI
Eric Wannemacher
h9p://upload.wikimedia.org/wikipedia/commons/thumb/5/52/Atlas_San'ago_Toural_GFDL.jpg/220px-‐Atlas_San'ago_Toural_GFDL.jpg
Give me a lever long enough and a fulcrum on which to place it, and I shall move the world. Archimedes
vs.
How Do I Use It?
• Things that are boring/repe''ve – Server builds – LUN migra'ons – Changing seRngs across many hosts/VMs – Reports for management/other teams – Managing mul'ple vCenters
• Things I should do, but may not otherwise – Configura'on monitoring – Log review
GeRng Started
• Install PowerShell (v2 if possible) • Run “Set-‐Execu'onPolicy RemoteSigned”
• Install PowerCLI 4.0 U1 (Maybe 4.1)
• Connect-‐VIServer <host or vCenter> • MAGIC
• Disconnect-‐VIServer
Demo Recipes
h9p://upload.wikimedia.org/wikipedia/commons/thumb/3/3d/Cheese_Soup_Recipe.jpg/800px-‐Cheese_Soup_Recipe.jpg
Making Toast
# List all VMs Get-VM
# Get one VM Get-VM ubuntu01
# Get VMs that match Get-VM ubuntu*
Boiling an Egg
# List VMs in a Datacenter
Get-Datacenter dc001 | Get-VM
# List VMs in a cluster
Get-Cluster dc001 | Get-VM
Sieing Through What You Have
# Get 2 CPU or larger VMs Get-VM | Where-Object {$_.NumCPU -ge 2}
# Get 2 GB RAM or larger VMs Get-VM | Where-Object {$_.MemoryMB -ge 2048}
Available Ingredients
Get-Command Get-VICommand Summarized By Noun h9p://wannemacher.us/?p=315
Get-Help Get-VM
Get-Member Get-VM | Get-Member
Addi'onal Info
• Local Resources – h9p://vmwarescrip'ng.com
– h9p://wannemacher.us
• Other – Managing VMware Infrastructure with Windows PowerShell TFM
– The VMware Community Forums (LucD) – Google