vmworld 2011 - powercli 101

22
PowerCLI 101

Upload: professionalvmware

Post on 23-Dec-2014

2.172 views

Category:

Technology


4 download

DESCRIPTION

Slides for PowerCLI 101 at VMworld 2011

TRANSCRIPT

Page 1: VMworld 2011 - PowerCLI 101

PowerCLI 101

Page 2: VMworld 2011 - PowerCLI 101

Why Automate

Save Time Reduce Risk Scale

Page 3: VMworld 2011 - PowerCLI 101

Agenda

Introduction to PowerShell vCenter management Storage management Automating VM lifecycle

Page 4: VMworld 2011 - PowerCLI 101

PowerShell 101 (Terminology)

Cmdlet (pronounced command-lets) are compiled .NET class that perfom a single action on an object. They are named in the <verb>-<singular noun> format.

Objects: A collection of properties and methods with a unique type name.

Pipeline: Passes whole .NET objects from one cmdlet to another enabling clean powerful syntax.

Page 5: VMworld 2011 - PowerCLI 101

PowerShell Pipeline

Get-

VM

Where

-Obje

ct

Sta

rt-V

M

Form

at-

Table

Pipeline in Action

Get-VM | Where-Object {$_.PowerState –eq ‘Powered Off’} | Start-VM | Format-Table

Page 6: VMworld 2011 - PowerCLI 101

PowerShell 101 ( Key Cmdlets)

Get-Command Get-Help Get-PSDrive Get-Member Format-List

Page 7: VMworld 2011 - PowerCLI 101

Grow Environment!Live Demo

Page 8: VMworld 2011 - PowerCLI 101

Needs & Environment

Tasks:• Create new datacenter• Add existing Host and VMs to new vCenter

instance.• Create a new cluster• Add new Host to the new cluster

Cmdlets used:• Connect-VIServer• New-Datacenter• Add-VMHost• New-Cluster• Set-Cluster• Move-VMHost

Page 9: VMworld 2011 - PowerCLI 101

Grow Environment

# Add host to vCenterConnect-VIServer vCenter01.sea-tm.netapp.com

# Create Datacenter$Datacenter = New-Datacenter -Name Bellevue -Location (Get-Folder)

# Add the first hostAdd-VMHost -Name vSphere1.sea-tm.netapp.com -Location $Datacenter ` -Force

# Create new cluster$Cluster = New-Cluster -Name VMworld -Location $Datacenter

# Set the HA/DRS Settings for our clusterSet-Cluster -cluster $Cluster -HAEnabled $True ` -HAIsolationResponse DoNothing -DrsEnabled $True -Confirm:$false

# Move our existing host into the new clusterMove-VMHost -VMHost vSphere1* -Destination $Cluster

# Add an additional host to the clusterAdd-VMHost -Name vSphere2.sea-tm.netapp.com -Location $Cluster ` -Force -RunAsync

Page 10: VMworld 2011 - PowerCLI 101

ZOMG I Needs Storage?!Live Demo

Page 11: VMworld 2011 - PowerCLI 101

Needs & Environment

Tasks:• Find and remove any large snapshots.• Provision new storage on Array• Add datastore to hosts• Move VMs to new storage.

Cmdlets used:• Get-VM• Get-Snapshot• Get-VMHost• New-Datastore• Sort-Object• Format-Table• Remove-Snapshot• Set-NaQtree• Set-NaNfsExport

• Move-VM• Get-Datastore• Connect-

NaController• New-NaVol• Set-NaSis• Enable-NaSis• Start-NaSis• Get-NaQtree

Page 12: VMworld 2011 - PowerCLI 101

ZOMG I Needs Storage?!

# Find any large snapshots.Get-VM|Get-Snapshot|Sort-Object SizeMB -Descending |Format-Table VM,Name,SizeMB

# Delete that sucka!Get-Snapshot -VM SQL01 -Name updates | Remove-Snapshot -RunAsync

# we're still a little tight... Create a new datastore!# Import the NetApp DataONTAP PowerShell ToolkitImport-Module DataONTAP

# Connect to the NetApp ControllerConnect-NaController 10.58.92.213

# Create a new volume, and configure dedupeNew-NaVol -Name vmdata1 -Aggregate aggr1 -SpaceReserve none -Size 10t | Set-NaSis -Schedule auto | Enable-NaSis | Start-NaSis | Get-NaQtree | Set-NaQtree -SecurityStyle unix

# Create the NFS exportSet-NaNfsExport -Persistent -Path /vol/vmdata1 -Root '172.16.3.0/24' ` -ReadWrite '172.16.3.0/24'

# Add datastoreGet-Cluster VMworld | Get-VMHost | New-Datastore -Name vmdata1 -Nfs ` -Path /vol/vmdata1 -NfsHost 172.16.3.213

# Move a VM to make some more room in our oversubscribed datastore.Get-VM Exch* | Move-VM -Datastore (Get-Datastore vmdata1) -RunAsync

Page 13: VMworld 2011 - PowerCLI 101

VM ProvisioningLive Demo!

Page 14: VMworld 2011 - PowerCLI 101

Needs & Environment

Tasks:• Clone an existing VM.• Create a new VM.• Convert VM to VM Template.• Deploy multiple VMs from Template.• Delete a VM.

Cmdlets used:• Get-Cluster• Get-Datacenter• Get-VM• Get-VMHost• New-VM• Remove-VM • Set-VM• ForEach-Object

Page 15: VMworld 2011 - PowerCLI 101

VM Provisioning

# We'll use this more than once!$vmhost = Get-Cluster -Name VMworld | Get-VMHost | Select -first 1

# Clone a VM for the ops team to test a patch.New-VM -Name SQL03_Clone -VM SQL03 -VMHost $VMHost -RunAsync

# Create a new VM$VM = New-VM -Name "AwesomeVM01" -VMHost $vmhost -DiskMB 61440 ` -MemoryMB 4196

# Now Make a template of that fool$template = $VM | Set-VM -ToTemplate -Name "VMworld Template"

# Add a force multiplier1..6| ForEach-Object { New-VM -Name "VM$_" -Template $template -VMHost $vmhost -RunAsync }

# Cleanup old VMGet-VM SQL03_Clone | Remove-VM -DeletePermanently

Page 16: VMworld 2011 - PowerCLI 101

Resources Books

Page 17: VMworld 2011 - PowerCLI 101

Resources Blogs

Page 18: VMworld 2011 - PowerCLI 101

Resources Blogs

Page 19: VMworld 2011 - PowerCLI 101

Resources Forums

Page 20: VMworld 2011 - PowerCLI 101

Resources Forums

Page 21: VMworld 2011 - PowerCLI 101

Resources Forums

Page 22: VMworld 2011 - PowerCLI 101

Where to go from here?

Books:• Learn Windows PowerShell in a Month of Lunches• VMware vSphere PowerCLI Reference

Blogs:• http://www.lucd.info/• http://www.virtu-al.net/

Forums:• http://www.vmware.com/go/PowerCLI• http://powershellcommunity.org• http://

social.technet.microsoft.com/Forums/en/ITCG/threads

Twitter: Use the hashtag #PowerShell #PowerCLI to get help.