270 likes | 598 Views
VSP1361 VMware vSphere PowerCLI 101 . Name, Title, Company. Why Automate. Save Time Reduce Risk Scale. Agenda. Introduction to PowerShell vCenter management Storage management Automating VM lifecycle. PowerShell 101 (Terminology).
E N D
VSP1361VMware vSpherePowerCLI 101 Name, Title, Company
Why Automate • Save Time • Reduce Risk • Scale
Agenda • Introduction to PowerShell • vCenter management • Storage management • Automating VM lifecycle
PowerShell 101 (Terminology) • Cmdlet(pronounced command-lets) are compiled .NET class that perfoma 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.
Pipeline in Action Get-VM | Where-Object {$_.PowerState –eq ‘Powered Off’} | Start-VM | Format-Table Get-VM Format-Table Where-Object Start-VM PowerShell Pipeline
PowerShell 101 ( Key Cmdlets) • Get-Command • Get-Help • Get-Module • Get-Member • Format-List
Grow Environment! Live Demo
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
Grow Environment # Add host to vCenter Connect-VIServervCenter01.sea-tm.netapp.com # Create Datacenter $Datacenter=New-Datacenter-NameBellevue-Location(Get-Folder) # Add the first host Add-VMHost-NamevSphere1.sea-tm.netapp.com-Location$Datacenter` -Force # Create new cluster $Cluster=New-Cluster-NameVMworld-Location$Datacenter # Set the HA/DRS Settings for our cluster Set-Cluster-cluster$Cluster-HAEnabled$True` -HAIsolationResponseDoNothing-DrsEnabled$True-Confirm:$false # Move our existing host into the new cluster Move-VMHost-VMHostvSphere1*-Destination$Cluster # Add an additional host to the cluster Add-VMHost-NamevSphere2.sea-tm.netapp.com-Location$Cluster` -Force-RunAsync
ZOMG I Needs Storage?! Live Demo
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
ZOMG I Needs Storage?! # Find any large snapshots. Get-VM|Get-Snapshot|Sort-ObjectSizeMB-Descending|Format-TableVM,Name,SizeMB # Delete that sucka! Get-Snapshot-VMSQL01-Nameupdates|Remove-Snapshot-RunAsync # we're still a little tight... Create a new datastore! # Import the NetApp DataONTAP PowerShell Toolkit Import-ModuleDataONTAP # Connect to the NetApp Controller Connect-NaController10.58.92.213 # Create a new volume, and configure dedupe New-NaVol-Namevmdata1-Aggregateaggr1-SpaceReservenone-Size10t| Set-NaSis-Scheduleauto | Enable-NaSis| Start-NaSis| Get-NaQtree| Set-NaQtree-SecurityStyleunix # Create the NFS export Set-NaNfsExport-Persistent-Path/vol/vmdata1-Root'172.16.3.0/24'` -ReadWrite'172.16.3.0/24' # Add datastore Get-Cluster VMworld |Get-VMHost|New-Datastore-Namevmdata1-Nfs` -Path/vol/vmdata1-NfsHost172.16.3.213 # Move a VM to make some more room in our oversubscribed datastore. Get-VMExch*|Move-VM-Datastore(Get-Datastorevmdata1)-RunAsync
VM Provisioning Live Demo!
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
VM Provisioning # We'll use this more than once! $vmhost=Get-Cluster-NameVMworld|Get-VMHost|Select-first1 # Clone a VM for the ops team to test a patch. New-VM-NameSQL03_Clone-VMSQL03-VMHost$VMHost-RunAsync # Create a new VM $VM=New-VM-Name"AwesomeVM01"-VMHost$vmhost-DiskMB61440` -MemoryMB4196 # Now Make a template of that fool $template=$VM|Set-VM-ToTemplate-Name"VMworld Template" # Add a force multiplier 1..6|ForEach-Object{ New-VM-Name"VM$_"-Template$template-VMHost$vmhost-RunAsync } # Cleanup old VM Get-VMSQL03_Clone|Remove-VM-DeletePermanently
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.