VMworld 2011 - PowerCLI 101

2,633 views

Published on

Slides for PowerCLI 101 at VMworld 2011

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
2,633
On SlideShare
0
From Embeds
0
Number of Embeds
375
Actions
Shares
0
Downloads
81
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • A healthy environment can only be maintained at scale with the use of automation. As a good general rule anything that will be done more than 10 times should be done via a script. The reason for selecting 10 as the demarcation point is due to the time investment. Generally speaking if you’re going to do something at least 10 times your organization will actually gain time by you taking the time to script a solution. Yes the script will take slightly longer to write the first time, but once written that script has no shelf life, and can be employed multiple times. Time spent manually performing a task can never be recuperated, and often leads to work having to be duplicated due to human error.
  • VMworld 2011 - PowerCLI 101

    1. 1. PowerCLI 101<br />
    2. 2. Why Automate<br />Save Time<br />Reduce Risk<br />Scale<br />
    3. 3. Agenda<br />Introduction to PowerShell<br />vCenter management<br />Storage management<br />Automating VM lifecycle<br />
    4. 4. PowerShell 101 (Terminology)<br />Cmdlet(pronounced command-lets) are compiled .NET class that perfoma single action on an object. They are named in the <verb>-<singular noun> format.<br />Objects: A collection of properties and methods with a unique type name.<br />Pipeline: Passes whole .NET objects from one cmdlet to another enabling clean powerful syntax.<br />
    5. 5. Get-VM | Where-Object {$_.PowerState –eq ‘Powered Off’} | Start-VM | Format-Table<br />Get-VM<br />Format-Table<br />Where-Object<br />Start-VM<br />PowerShell Pipeline<br />Pipeline in Action<br />
    6. 6. PowerShell 101 ( Key Cmdlets)<br />Get-Command<br />Get-Help<br />Get-PSDrive<br />Get-Member<br />Format-List<br />
    7. 7. Grow Environment!<br />Live Demo<br />
    8. 8. Needs & Environment<br />Tasks:<br /><ul><li>Create new datacenter
    9. 9. Add existing Host and VMs to new vCenter instance.
    10. 10. Create a new cluster
    11. 11. Add new Host to the new cluster </li></ul>Cmdlets used:<br /><ul><li>Connect-VIServer
    12. 12. New-Datacenter
    13. 13. Add-VMHost
    14. 14. New-Cluster
    15. 15. Set-Cluster
    16. 16. Move-VMHost</li></li></ul><li>Grow Environment<br /># Add host to vCenter<br />Connect-VIServervCenter01.sea-tm.netapp.com<br /># Create Datacenter<br />$Datacenter=New-Datacenter-NameBellevue-Location(Get-Folder)<br /># Add the first host<br />Add-VMHost-NamevSphere1.sea-tm.netapp.com-Location$Datacenter`<br />-Force<br /># Create new cluster<br />$Cluster=New-Cluster-NameVMworld-Location$Datacenter<br /># Set the HA/DRS Settings for our cluster<br />Set-Cluster-cluster$Cluster-HAEnabled$True`<br />-HAIsolationResponseDoNothing-DrsEnabled$True-Confirm:$false<br /># Move our existing host into the new cluster<br />Move-VMHost-VMHostvSphere1*-Destination$Cluster<br /># Add an additional host to the cluster<br />Add-VMHost-NamevSphere2.sea-tm.netapp.com-Location$Cluster`<br />-Force-RunAsync<br />
    17. 17. ZOMG I Needs Storage?!<br />Live Demo<br />
    18. 18. Needs & Environment<br />Tasks:<br /><ul><li>Find and remove any large snapshots.
    19. 19. Provision new storage on Array
    20. 20. Add datastore to hosts
    21. 21. Move VMs to new storage.</li></ul>Cmdlets used:<br /><ul><li>Get-VM
    22. 22. Get-Snapshot
    23. 23. Get-VMHost
    24. 24. New-Datastore
    25. 25. Sort-Object
    26. 26. Format-Table
    27. 27. Remove-Snapshot
    28. 28. Set-NaQtree
    29. 29. Set-NaNfsExport
    30. 30. Move-VM
    31. 31. Get-Datastore
    32. 32. Connect-NaController
    33. 33. New-NaVol
    34. 34. Set-NaSis
    35. 35. Enable-NaSis
    36. 36. Start-NaSis
    37. 37. Get-NaQtree</li></li></ul><li>ZOMG I Needs Storage?!<br /># Find any large snapshots.<br />Get-VM|Get-Snapshot|Sort-ObjectSizeMB-Descending|Format-TableVM,Name,SizeMB<br /># Delete that sucka!<br />Get-Snapshot-VMSQL01-Nameupdates|Remove-Snapshot-RunAsync<br /># we're still a little tight... Create a new datastore!<br /># Import the NetApp DataONTAP PowerShell Toolkit<br />Import-ModuleDataONTAP<br /># Connect to the NetApp Controller<br />Connect-NaController10.58.92.213<br /># Create a new volume, and configure dedupe<br />New-NaVol-Namevmdata1-Aggregateaggr1-SpaceReservenone-Size10t|<br />Set-NaSis-Scheduleauto | Enable-NaSis| Start-NaSis| Get-NaQtree| <br />Set-NaQtree-SecurityStyleunix<br /># Create the NFS export<br />Set-NaNfsExport-Persistent-Path/vol/vmdata1-Root'172.16.3.0/24'`<br />-ReadWrite'172.16.3.0/24'<br /># Add datastore<br />Get-Cluster VMworld |Get-VMHost|New-Datastore-Namevmdata1-Nfs`<br />-Path/vol/vmdata1-NfsHost172.16.3.213<br /># Move a VM to make some more room in our oversubscribed datastore.<br />Get-VMExch*|Move-VM-Datastore(Get-Datastorevmdata1)-RunAsync<br />
    38. 38. VM Provisioning<br />Live Demo!<br />
    39. 39. Needs & Environment<br />Tasks:<br /><ul><li>Clone an existing VM.
    40. 40. Create a new VM.
    41. 41. Convert VM to VM Template.
    42. 42. Deploy multiple VMs from Template.
    43. 43. Delete a VM.</li></ul>Cmdlets used:<br /><ul><li>Get-Cluster
    44. 44. Get-Datacenter
    45. 45. Get-VM
    46. 46. Get-VMHost
    47. 47. New-VM
    48. 48. Remove-VM
    49. 49. Set-VM
    50. 50. ForEach-Object</li></li></ul><li>VM Provisioning<br /># We'll use this more than once!<br />$vmhost=Get-Cluster-NameVMworld|Get-VMHost|Select-first1<br /># Clone a VM for the ops team to test a patch.<br />New-VM-NameSQL03_Clone-VMSQL03-VMHost$VMHost-RunAsync<br /># Create a new VM<br />$VM=New-VM-Name"AwesomeVM01"-VMHost$vmhost-DiskMB61440`<br />-MemoryMB4196<br /># Now Make a template of that fool<br />$template=$VM|Set-VM-ToTemplate-Name"VMworld Template"<br /># Add a force multiplier<br />1..6|ForEach-Object{<br />New-VM-Name"VM$_"-Template$template-VMHost$vmhost-RunAsync<br />}<br /># Cleanup old VM<br />Get-VMSQL03_Clone|Remove-VM-DeletePermanently<br />
    51. 51. Resources Books<br />
    52. 52. Resources Blogs<br />
    53. 53. Resources Blogs<br />
    54. 54. Resources Forums<br />
    55. 55. Resources Forums<br />
    56. 56. Resources Forums<br />
    57. 57. Where to go from here?<br />Books:<br /><ul><li>Learn Windows PowerShell in a Month of Lunches
    58. 58. VMware vSphere PowerCLI Reference</li></ul>Blogs:<br /><ul><li>http://www.lucd.info/
    59. 59. http://www.virtu-al.net/</li></ul>Forums:<br /><ul><li>http://www.vmware.com/go/PowerCLI
    60. 60. http://powershellcommunity.org
    61. 61. http://social.technet.microsoft.com/Forums/en/ITCG/threads</li></ul>Twitter: Use the hashtag #PowerShell #PowerCLI to get help.<br />

    ×