Your SlideShare is downloading. ×
PowerCLI Workshop
Upcoming SlideShare
Loading in...5

Thanks for flagging this SlideShare!

Oops! An error has occurred.


Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

PowerCLI Workshop


Published on

v1 of my PowerCLI Workshop. Download the scripts at

v1 of my PowerCLI Workshop. Download the scripts at

Published in: Technology

  • Hello Carter, you have published good stuff! THANKS!
    Though i would like to use the 'Demo' but am not able to do so. Can you please advise me in this so that i can use the 'Demo's'?

    Thanks so far,
    Are you sure you want to  Yes  No
    Your message goes here
  • Hi Carter, thanks for the document. Very useful stuff!!
    I am not able to click on the demo? Can you please advise me in this?

    Thanks in advance,
    Are you sure you want to  Yes  No
    Your message goes here
  • This is the ultimate in vSphere PowerCLI Training ! For folks that prefer an instructor led course
    VMware provides a new course for new PowerCLI users;

    Course Title: VMware vSphere Automation available in the VMware Training Catalog.
    2 Day instructor led training, organizations can also use their PSO credits for course.

    Links to course are on the PowrCLI Home Page
    Are you sure you want to  Yes  No
    Your message goes here
  • Download the scripts at
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

No notes for slide
  • This picture is an old time accounting department. Used to be tens or hundreds of mathematicians or statisticians would sit around doing calculations and double-checking figures.
  • These days spreadsheets do the work of hundreds of calculators, and nobody thinks twice about it. Technology enabled a shift. A fundamental change in the way people did things.
  • Demo Script: MostUsedCmdlets.ps1
  • Demo Script: ImportCSV.ps1
  • Demo Script: 5Minute.ps1
  • Demo Script: LargeProvisioning.ps1
  • Demo Script: LargeUpdate.ps1
  • Demo Script: Snapshots.ps1
  • Demo Script: HostProfiles.ps1
  • Demo Script: Clusters.ps1
  • Demo Script: VMotionStorageVMotion.ps1
  • Demo Script: ThinProvision.ps1
  • Demo Script: NFS.ps1
  • Demo Script: MoveVMNetwork.ps1
  • Demo Script: VirtualSwitch.ps1
  • Demo Script: GuestDisk.ps1
  • Demo Script: Waste.ps1
  • Demo Script: CustomAttributes.ps1
  • Demo Script: RolesPermissions.ps1
  • Demo Script: StatsIntro.ps1
  • Demo Script: TopVMHost.ps1
  • Demo Script: EventReports.ps1
  • Demo Script: VMLastPoweron.ps1
  • Demo Script: ReadableCode.ps1
  • Demo Script: MaxSpeed.ps1
  • Demo Script: ObjectExtensions.ps1
  • Demo Script: GetViewGetMember.ps1
  • No script for this demo.
  • Demo Script: GuestManagement.ps1
  • Demo Script: ChangeSwap.ps1
  • Demo Script: iSCSI.ps1
  • Demo Script: RDM.ps1
  • Demo Script: UnsharedVMs.ps1
  • Demo Script: RDM.ps1
  • Demo Script: QueueDepth.ps1
  • Demo Script: AdvancedSwitch.ps1
  • Demo Script: ESXAdvancedConfig.ps1
  • Demo Script: Licensing.ps1
  • Demo Script: FindBottlenecks.ps1
  • Demo Script: ArchiveLogfiles.ps1
  • Demo Script: Alarms.ps1
  • Demo Script: RegisterVMs.ps1
  • Demo Script: RDMReport.ps1
  • Demo Script: ESXDNS.ps1
  • Transcript

    • 1. vSphere PowerCLI
      The best tool for automating vSphere
    • 2. Introduction.
      About me.
      Product Manager – APIs and platform. (@cshanklin)
      Did you know?
      Most of the world’s top virtualization experts use twitter?
    • 3. The Purpose of PowerCLI.
      PowerCLI is a tool for automating all aspects of vSphere management and administration.
      But PowerCLI is different because it’s purpose-built for use by administrators, not developers.
      “Any knowledgeable vSphere administrator can look at PowerCLI code and immediately understand what it does.”
    • 4. You need automation to survive the virtual world.
      Virtual assets are extremely easy to create.
      Some people call it “virtual sprawl”.
      But virtualization lets us do so much more – more complexity is inevitable.
      Tools and skill sets must be upgraded to match this rise in complexity.
    • 5. Financial analysis – then.
    • 6. Financial analysis – now.
    • 7. PowerCLI changes the nature of your work.
      In a lot of ways the current state of virtual management is like the accounting department from the 50s. A lot of manual labor.
      Complex automation used to be only accessible to dedicated development teams.
      But PowerCLI empowers you to do complex automation yourself.
    • 8. How to get the most out of PowerCLI.
      Remember that PowerCLI can automate anything in vSphere.
      Think about how these possibilities can change the nature of the things you do every day.
      Focus on increasing your productivity.
      Stop doing things manually.
      Start focusing on building automation tools
      you can use again and again.
    • 9. Overview / Agenda.
      Getting to know you.
      Introduction to PowerShell.
      Introduction to PowerCLI.
      Managing VMs with PowerCLI.
      Managing ESX with PowerCLI.
      Managing Storage with PowerCLI.
      Managing Network with PowerCLI.
    • 10. Overview / Agenda (cont).
      Other PowerCLI topics.
      Advanced: Intro to the API.
      Advanced Storage.
      Advanced Network.
      Advanced ESX.
      Other Advanced Topics.
    • 11. Getting to know you.
      How are you using PowerCLI today?
      Would you say you’re a beginner? Expert?
      How does PowerCLI integrate into your other management practices?
      What things do you wish PowerCLI could do for you?
      How do you manage physical + virtual? What is lacking here?
      What key things did you hope to learn?
    • 12. Getting to know you.
      Where are you wasting your time?
      Change management?
      What business pressures do you face?
      Supporting a wider variety of applications?
      Improving availability?
      Other things?
    • 13. Intro To PowerShell
    • 14. Top 5 things to know about PowerShell.
      The purpose.
      The cmdlets.
      The pipeline.
      The platforms.
      The products.
    • 15. PowerShell: The Purpose.
      IT systems are getting more complex and inter-connected.
      Virtualization leads to explosive growth in the number of assets (network, app, etc) to manage.
      Automation is becoming a valuable and needed skill for IT administrators.
      PowerShell allows non-programmers
      to automate.
    • 16. PowerShell: The cmdlets.
      PowerShell provides almost 200 commands, called cmdlets, natively.
      Close to 1,000 more commands are available through various “snap-ins” (e.g. PowerCLI).
      Within PowerShell, type “Get-Command” to see a listing of commands.
    • 17. PowerShell: The Pipeline.
      The pipeline is how you compose commands in PowerShell.
      Outputs of one command are automatically made inputs of the next, based on type.
      Get-Process notepad | Stop-Process
      Get-VM myvm | Start-VM
    • 18. PowerShell: The Platforms.
      PowerShell runs on all versions of Windows since XP and up.
      Requires .NET 2.0.
      PowerShell is installed by default in Windows 7 and Windows 2008 R2.
      All future versions of Windows will pre-install it.
    • 19. PowerShell: The Products.
      PowerShell support is required for all Microsoft server applications.
      Many more.
      And, of course, VMware.
    • 20. The top 9 most used cmdlets.
    • 21. The top 9 most used operators.
    • 22. How well do you know PowerShell?
      Would you say you’re more novice or expert?
      Are you using PowerShell to manage other things such as exchange?
      Do you view PowerShell as a strategic direction for your IT OPS?
      Are the people picking up PowerShell more “Windows people” or “UNIX people”?
    • 23. Most Used PowerShell Cmdlets and Operators.
    • 24. 3 Takeaways: Most used cmdlets.
      PowerShell provides hundreds of commands that interoperate with VMware commands.
      Microsoft continues to invest and expand PowerShell’s reach.
      PowerShell + PowerCLI makes it possible to manage everything from virtual infrastructure to guest.
    • 25. One bonus cmdlet you will need to automate!
      Imports a spreadsheet.
      Great for doing anything at large scale.
      Learn this pattern and technique you won’t regret it!
    • 26. Using Import-CSV.
      Key cmdlets:
    • 29. 3 Takeaways: Import-CSV.
      Get familiar with Import-CSV!
      Two types of automation:
      Make the same change to every object in a large set.
      Make a different change to each object in a large set.
      Import-CSV is an ideal choice for solving the second problem.
    • 30. 5 PowerShell tools you should use.
      VESI (Virtualization EcoShell).
      Virtu-Al.Net vSphere PowerPack.
      PowerShell WMI Explorer.
      PowerShell Plus.
    • 31. Intro To PowerCLI
    • 32. Top 5 things to know about PowerCLI.
      The purpose.
      The cmdlets.
      Cmdlet Tetris.
      The products.
      The future.
    • 33. PowerCLI: The Purpose.
      You need automation.
      Because it’s so easy to create virtual assets.
      Because you need to keep up with the other guy.
      PowerCLI is automation for everyone.
      Reduce the distance between person who understands the problem and person who solves it.
      PowerCLI is comprehensive. Everything
      vCenter can do.
    • 34. PowerCLI: The Cmdlets.
      229 cmdlets in version 4.0 U1.
      Built on the vSphere Web Services API.
      Two ways to automate:
      Simplified cmdlet approach.
      Advanced approach using Get-View (API).
      More coming every 6 months or so.
      PowerCLI release philosophy is to release twice a year and be very responsive to user feedback.
      Long-term goal to make Get-View
    • 35. PowerCLI: Cmdlet Tetris.
      PowerShell commands follow the pattern Verb-Noun or Verb-Object.
      For a given Object you will commonly see these four commands:
      New-Object, Get-Object, Set-Object, Remove-Object
      Look for this pattern to manage the full lifecycle of a virtual object.
    • 36. PowerCLI: The Products.
      2.5, 4.0
      ESX / ESXi
      3.0, 3.5, 4.0
      VMware Update Manager (preview)
    • 37. PowerCLI: The Future.
      Continue to simplify automation until it is truly accessible to everyone.
      Broaden the product portfolio to other solutions such as SRM, vCloud, etc.
      Provide a more structured experience (i.e. not “just a bunch of scripts on some network share”)
    • 38. Making sense of it all.
    • 39. Where do you feel the most pain?
      Configuring and maintaining ESX hosts?
      Performance analysis?
    • 40. Use Cases and Demos
    • 41. PowerCLI Support Matrix (4.0 U1) (Latest)
      Windows Vista (32 and 64 bit)
      Windows 2003 (32 and 64 bit)
      Windows XP
    • 42. PowerCLI Support Matrix (4.1) (Future!)
      Windows 7 (32 and 64 bit)
      Windows 2008 (32 and 64 bit)
      Windows Vista (32 and 64 bit)
      Windows 2003 (32 and 64 bit)
      Windows XP
    • 43. 3 ways to connect.
      Use your username and password.
      Warning: don’t do this except interactively.
      Use SSPI / Active Directory if you have it.
      Use Import-PSCredential if you don’t.
    • 44. Tips
      A 5-minute introduction to PowerCLI.
      Key cmdlets:
    • 47. 3 Takeaways: 5 minute intro.
      PowerCLI provides more than 200 commands and it’s growing all the time.
      PowerCLI manages everything that vCenter manages and more.
      PowerCLI makes automation easy enough that anyone can do it.
    • 48. Get-TheMost out of “Help”
      Help is PowerShell’s built-in help system.
      Everything you need to know is documented in the cmdlet itself.
      Supports wildcards “Help *VM*”
      All PowerCLI cmdlets have examples.
      “Help <cmdlet> -examples”
      “Help <cmdlet> -full”
    • 49. Get-TheMost out of “Get” cmdlets.
      Learn how to string Get-Cmdlets together.
      Example: Get-Cluster X | Get-VMHost | Get-VM to select all VMs in a cluster.
      PowerCLI cmdlets are designed to navigate similar to the vSphere Client hierarchy.
      But PowerCLI can do things vSphere Client can’t.
      You can learn this from them help but easier
      to just try it out.
    • 50. PowerCLI supports multiple connections.
      Starting in PowerCLI 4.0 U1 you can connect to multiple vCenter or ESX servers at the same time.
      Now you can automate across multiple vCenters or across multiple ESX even if vCenter is unavailable.
    • 51. The top 9 VM-related cmdlets.
    • 52. Managing VMs with PowerCLI.
      Change / Update.
      Change its resource allocation (e.g. memory).
      Change its networking.
      Add/remove storage.
      VMware Tools.
    • 53. What challenges do you face around VMs?
      Do you tend to provision VMs in bunches or one-at-a-time?
      What software do you use to provision?
      How do you provision lots of VMs? How often?
      Do you use templates or PXE-based builds?
      How are you increasing your VM management ratios?
      How do you detect wasted VM resources?
    • 54. 3 ways to provision your VMs.
      Creating blank VMs and PXE booting them.
      Clone a template.
      Clone a VM while running.
    • 55. VMs
      Provisioning at large scales.
      Key cmdlets:
      • New-VM
      • 56. Get-Template
      • 57. Get-OSCustomizationSpec
    • 58. 3 Takeaways: Large-scale provisioning.
      Whether you use templates or not, PowerCLI makes it easy to provision.
      Even if you use static IP addresses PowerCLI can automate it.
      Large-scale provisioning and Import-CSV were virtually made for each other.
    • 59. VMs
      Large-scale VM Updates.
      Key cmdlets:
    • 61. 3 Takeaways: VM Updates.
      Large-scale updates are easy with Set-VM.
      Master Get-* and Where cmdlets to target exactly the VMs you want.
      If you’re worried about the impact, use –whatif.
    • 62. VMs
      Dealing with snapshots.
      Key cmdlets:
    • 65. 3 Takeaways: Snapshots.
      Snapshots are the “silent datastore killer”.
      Track their age and size with PowerCLI.
      Deleting lots of snapshots is a snap (sorry).
    • 66. The top 8 ESX-related cmdlets.
    • 67. Managing ESX with PowerCLI.
      Provisioning (Host profiles or scripted)
      Change / Update.
      Security, etc.
      Managing power and connection state.
    • 68. What challenges do you face deploying ESX?
      What software do you use to deploy?
      How do you track inventory and monitor ESX?
      How do you manage the ESX / vCenter relationship?
      How do you manage storage and network to your ESX systems?
      How are you planning to deal with ESXi?
    • 69. 2 ways to provision your ESX hosts.
      Host Profiles.
      Provision one server just the way you like it.
      “Stamp out” the configuration to other servers.
      Home-grown scripts (covered later).
      Run a custom script to do complete configuration of a server.
    • 70. ESX
      Dealing with Host Profiles.
      Key cmdlets:
      • Get-VMHostProfile
      • 71. Apply-VMHostProfile
      • 72. Test-VMHostProfileCompliance
    • 73. 3 Takeaways: Host Profiles.
      Host Profiles simplify the process of creating identically configured ESX hosts.
      The purpose of profiles is avoiding cost and complexity “I don’t have to worry about a million things.”
      Host Profiles are a strategic direction for VMware and will continue to improve.
    • 74. Why we cluster.
      Clustering is the heart of VMware’s real value.
      High availability.
      Automated resource management and balancing.
      PowerCLI gives complete and granular control over cluster configuration.
    • 75. ESX
      Clustering your hosts for max availability.
      Key cmdlets:
    • 78. 2 Takeaways: Clustering.
      In the past all interesting VMware functionality happened at the host level. Recently this has been moving to cluster (eventually to datacenter).
      PowerCLI gives you the tools you need to configure, monitor and audit your clusters.
    • 79. You can also automate DRS rules.
      Key cmdlets:
    • 80. The top 9 storage-related cmdlets.
    • 81. Managing Storage with PowerCLI.
      Adding existing datastores or formatting new.
      Rescanning storage.
      Capacity and utilization reports.
      Identifying datastores that are not visible to the entire cluster.
    • 82. What challenges do you face around storage?
      Do you have a dedicated storage team? How well do storage and virtualization interact?
      Do you have separate storage management tools?
      How do you identify and resolve storage bottlenecks?
      When users complain about slow applications, what do you do?
    • 83. Storage VMotion is a snap.
      Move-VM is a versatile command.
      If you use –Datastore you will Storage VMotion.
    • 84. Storage
      VMotion and Storage VMotion with Move-VM.
      Key cmdlets:
    • 87. 3 Takeaways: Storage VMotion.
      Performing a Storage VMotion can take a really long time.
      Perfect reason to script it.
      Try to beat this simplicity:
      Get-VM –Datastore ds1 | Move-VM –Datastore ds2
    • 88. Save money with thin provisioning.
      Allocate space as it is used rather than all at once.
      Huge space savings at the cost of some performance.
      You can provision new VMs thin or convert existing with PowerCLI.
    • 89. Storage
      Thin Provisioning.
      Key cmdlets:
    • 92. 3 Takeaways: Thin Provisioning.
      Storage is expensive! Why pay for the parts you’re not using?
      With simple PowerCLI scripts you can change existing VMs to use thin provisioning.
      Or just build an easy report to see how much you’re using or how much you could save.
    • 93. Storage
      Adding NFS Datastores to ESX.
      Key cmdlets:
      • New-Datastore
    • 94. 2 Takeaways: NFS Datastores.
      Adding and auditing NFS datastores is simple with PowerCLI.
      Warning: NFS performance statistics are not available (coming in a future version of vSphere).
    • 95. The top 9 network-related cmdlets.
    • 96. Managing Networking with PowerCLI.
      Adding or configuring VMKernel.
      Moving VMs between virtual switches.
      Configuring virtual switch policies.
    • 97. What challenges do you face around network?
      How do you manage the interaction between virtual and physical switch? Example: VLAN, CDP.
      How do you ensure consistent network configuration across ESX hosts?
      Do you use trunking for max performance? Have you encountered problems doing this?
    • 98. Network
      Moving VMs between networks.
      Key cmdlets:
      • Get-NetworkAdapter
      • 99. Set-NetworkAdapter
    • 100. 2 Takeaways: Changing VM Networks.
      Moving VMs from one network to another is quick and easy.
      If a virtual switch is re-created, on purpose or by accident, your VMs will all be disconnected. You can solve that with one line of PowerCLI.
    • 101. Network
      Configuring Consistent Virtual Switches.
      Key cmdlets:
      • New-VirtualSwitch
      • 102. Get-VirtualSwitch
    • 103. 3 Takeaways: Virtual Switches.
      Creating consistent virtual switches is key for many VMware features such as DRS.
      Creating switches manually is insane, especially considering the simplicity of PowerCLI.
      You can also set policy items like failover and load balancing (covered later).
    • 104. The top 5 reporting cmdlets.
    • 105. Reporting with PowerCLI.
      Three major categories of PowerCLI reports.
      Inventory-based reporting.
      Statistic-based reporting (i.e. performance)
      Event-based reporting.
    • 106. Reporting with PowerCLI.
      What reporting tools do you use today? Do you think they are good?
      Do you use reports more for planning or more for reacting to problems?
      Where do you feel you are “in the dark”?
    • 107. Inventory-based reporting.
      Relies on Get-* cmdlets as a starting point.
      Generally combined with Export-CSV or ConvertTo-Html.
    • 108. Report on your guest disk capacity.
      Basic report.
      Sort by least % free space.
      Show all guests with <10% free space.
    • 109. Reports
      Reporting on Guest Disk Capacity.
      Key cmdlets:
    • 111. 3 Takeaways: Guest Disks.
      Relies on VMware Tools!
      Avoid a disaster by identifying disks that are about to overflow.
      Also makes it easy to understand how much thin provisioning would save you.
    • 112. 3 ways to report on wasted resources.
      Orphaned VMDKs. – script not working now
      Unused VMs.
    • 113. Reports
      Reporting on Wasted Resources.
      Key cmdlets:
    • 115. 3 Takeaways: Wasted Resources.
    • 116. Reporting with custom attributes.
      Custom attributes are extremely useful for tracking things unique to your deployment.
      Example: VM owner, app owner, etc.
    • 117. Reports
      Reporting with Custom Attributes.
      Key cmdlets:
      • Get-CustomAttribute
      • 118. Get-Inventory
    • 119. 3 Takeaways: Custom Attributes.
      If you’re not using custom attributes – start!
      Audit your custom attributes to determine compliance (all the data is there and accurate)
      You should set attributes as part of your provisioning process.
    • 120. Reports
      Security reporting using roles and permissions.
      Key cmdlets:
    • 122. 3 Takeaways: Roles and Permissions.
      PowerCLI gives you all the tools you need to audit roles and permissions.
      With Quest’s ActiveRoles you can load Active Directory information for more useful reports.
      With PowerCLI you can easily duplicate roles and permissions between vCenter instances.
    • 123. Statistic-based reporting.
      Relies on Get-Stat as a starting point.
      Commonly you will rank the results.
      This can feed into other script logic or be exported like an inventory report would be exported.
    • 124. Get-TheMost out of Get-Stat.
      Get-StatType identifies available statistics.
      Understanding instances is critical.
      Note: vCenter and ESX may report different types of statistics.
    • 125. Reports
      Introduction to statistic-based reporting.
      Key cmdlets:
      • Get-Stat
    • 126. 3 Takeaways: Reporting with Statistics.
      Querying statistics help you identify and solve performance problems.
      Stats on vCenter are determined by stat level. The higher the level the more stats you have.
      If you query ESX directly all stats are available but for short periods (5 mins on 3.5, 1hr on 4.0)
    • 127. Top 8 Most Interesting Statistics.
    • 128. Reports
      Most and least busy VMs and Hosts.
      Key cmdlets:
      • Get-Stat
    • 129. 2 Takeaways: Host and VM Usage.
      Identifying overused resources it the first step to effective rebalancing.
      With PowerCLI you get a complete picture all at once no matter how many hosts or VMs you have.
    • 130. Event-based reporting.
      Relies on Get-VIEvent as a starting point.
      Most vSphere actions create events in order to generate an audit trail.
      This audit trail can be followed and inspected for a large number of uses.
    • 131. Reports
      Introduction to event-based reporting.
      Key cmdlets:
      • Get-VIEvent
    • 132. 3 Takeaways: Event-based reporting.
      Events tell you who did what when.
      ESX retains a fixed number of events, vCenter retains all events since a given date.
      Before you report events be sure to understand your vCenter’s event retention policy.
    • 133. Reports
      When was that VM powered on?
      Key cmdlets:
      • Get-VIEvent
    • 134. 3 Takeaways: Determining VM Poweron Date.
      Just one of many reports you can do with events.
      If an outage occurs you can find which modifications may have contributed to the outage using –Start and –Finish.
      Track who logged in and when.
    • 135. You can get your VM’s log file too.
      Get to know vmstore:
      Use Copy-DatastoreItem to bridge the gap between local and remote.
    • 136. This report will make your manager love you (in a completely legal way).
      Alan Renouf’s Daily Report.
      Numbers of objects in inventory (VMs, hosts, etc)
      Datastores running out of space.
      Snapshots over X days old.
      Disconnected hosts.
      Lots more!
      All emailed to you every morning!
    • 137. Stuff Alan’s Daily Report Will Tell You.
      Number of Hosts
      Number of VMs
      Number of Datastores
      Number of DRS Migrations for the last days
      Snapshots over x Days old
      Datastores with less than x% free space
      VMs created over the last x days
      VMs with No Tools
      VMs with CD-Roms connected
      VMs with CPU ready over x%
      Hosts in Maintenance Mode
      VC Error Events over the last x days
      VC Windows Event Log Errors for the last x days with VMware in the details
      VM active alerts
      Cluster Active Alerts
      vSphere check: Outdated VM Hardware (Less than V7)
      VMs in Inconsistent folders (the name of the folder is not the same as the name)
    • 138. Sample Daily Report Output.
    • 139. The top 9 other cmdlets.
    • 140. Top 5 PowerCLI FAQs (With answers!)
      How to upgrade VMware Tools with no reboot?
      How to move only one disk during Storage VMotion?
      How to change the ESX host’s root password?
      How do I take lots of actions simultaneously?
      How to get the VM’s UUID?
    • 141. Top 5 PowerCLI FAQs (With answers!)
      How to upgrade VMware Tools with no reboot?
      New in PowerCLI 4.0 U1, Update-Tools –NoReboot
      How to move only one disk during Storage VMotion?
      Use Set-HardDisk –Datastore.
      Bug: Requires the VM to be powered off. This is fixed in 4.1.
    • 142. Top 5 PowerCLI FAQs (With answers!)
      How to change the ESX host’s root password?
      Connect directly to the ESX host.
      Use Get-VMHostAccount / Set-VMHostAccount.
      How do I take lots of actions simultaneously?
      Most PowerCLI commands support the –Runasync flag, which causes jobs to run in the background.
      Use this along with Wait-Task.
    • 143. Top 5 PowerCLI FAQs (With answers!)
      How to get the VM’s UUID?
      Inside the view property config.uuid
      Get-VM | Select Name, { ($_ | Get-View).config.uuid }
      Or using object extensions (upcoming feature).
    • 144. Secure your scripts with these tips.
      You can configure PowerShell to not run unsigned scripts.
      PowerShell Plus has built-in script signing.
    • 145. 3 mistakes you need to avoid!
      Careful when using New-Snapshot!
      Use –Memory if you want to revert to the snapshot without powering the VM off.
      Careful when deleting that VM!
      If you don’t use –DeleteFromDisk it will simply be unregistered.
      Don’t use Write-Host!
      Except as debugging, instead use
    • 146. 4 tips to make your scripts more readable
      Use object names rather than separate cmdlet calls.
      Use line continuation (backticks) when necessary.
      Factor code into functions.
      Use PowerGUI, VESI, or PowerShell Plus for syntax highlighting.
    • 147. Tips
      Maximizing readability and maintainability.
    • 148. 3 Takeaways: Readability.
      Readable code is maintainable code.
      Take maximum advantage of Object-By-Name.
      The pipeline separates PowerShell from other languages. Use it a lot and your readability will greatly improve.
    • 149. Tips
      Speeding up your scripts.
    • 150. 3 Takeaways: Speeding up your scripts.
      PowerShell does not optimize scripts. Factor variables out manually.
      Be aware of the performance penalties OBN introduces. If you have the object handy, don’t use its name.
      If your scripts are slow, consider caching more objects client-side.
    • 151. 1 feature you absolutely need to know.
      Object Extensions.
      Is your favorite object missing a property? Add it yourself!
      This will fundamentally change the way you script and report.
      “PowerCLI 2.0”
    • 152. Tips
      Simplifying Reporting With Object Extensions.
      Key cmdlets:
      • New-VIObjectExtensionProperty
      • 153. (Name subject to change)
      Demo (Future Features)
    • 154. 3 Takeaways: Object Extensions.
      Object Extensions will radically simplify your scripts and reports.
      If you ever wished an object had a certain property or field, find it in the API and you will soon be able to add it yourself.
      Coming soon in PowerCLI 4.1.
    • 155. Learn to write a PowerShell Advanced Function
      PowerShell Advanced Functions function almost exactly like PowerShell cmdlets.
      You can write scripts that:
      Sit in the PowerShell pipeline.
      Interoperate with all PowerCLI cmdlets.
      “help about_functions_advanced”.
      See “VI Toolkit Extensions” for samples.
    • 156. Learn to write a PowerShell Advanced Function
      PowerShell Advanced Functions function almost exactly like PowerShell cmdlets.
      You can write scripts that:
      Sit in the PowerShell pipeline.
      Interoperate with all PowerCLI cmdlets.
      “help about_functions_advanced”.
      See “VI Toolkit Extensions” for samples.
    • 157. Anatomy of an advanced function.
      functionAdvanced-Function {
      Begin {
      Process {
      End {
      Initialize at the start of the pipeline (opt)
      Process each object in the pipeline.
      Called at the end of the pipeline (opt)
    • 158. Sample advanced function: ESX Host Routes.
    • 159. Resources
    • 160. 3 must-own resources:
      Managing VMware Infrastructure with Windows PowerShell.
      vSphere 4.0 Quick Start Guide.
      VMware vSphere Pro Series Training.
    • 161. The “PowerCLI Bible”
    • 162. Lots of PowerCLI Samples.
    • 163. New training from TrainSignal!
    • 164. 6 Amazing Blogs to Follow:
    • 165. The most important resource of all:
      The PowerCLI Community.
      More than 500 scripts.
      Search a huge and growing knowledgebase.
      Ask questions and get answers.
    • 166. By Sheer Coincidence.
      PowerShell Master Class [3 dagar]
      Instructor: Thomas Lee, PowerShell MVP
      Begins 2010-03-09
    • 167. Advanced Stuff!
    • 168. The vSphere API Stack.
    • 169. Managed objects and automation objects.
      PowerCLI uses two object models.
      Automation objects: Small objects containing only the most critical data. Returned by Get-* cmdlets (example Get-VM).
      View objects: Full objects with no properties missing. Not optimized for usability.
      You can easily transition between the two.
      Get-View: Automation to view object.
      Get-VIObjectByVIView: View to automation.
    • 170. Explore the vSphere API with PowerCLI.
      Get-View is your gateway to the API.
      You can pipe most objects to Get-View.
      Some objects have hard-coded names and can must be loaded directly.
      E.g. Get-View ServiceContent
    • 171. You can do anything with Get-View.
      When you load a view with Get-View all its properties and methods are available to you.
      You can see all this with PowerShell’s Get-Member cmdlet.
    • 172. API
      Use Get-View and Get-Member to explore the API.
      Key cmdlets:
    • 174. 4 Takeaways: Get-View.
      Get-View opens the full power of the API to you.
      You can do anything vCenter can do using this API.
      But: you have to use the vSphere API, which can be quite challenging.
      Refer to the docs:
    • 175. Surviving the vSphere API Documentation.
      Most useful starting points: Search within:
      All managed objects – OR –
      All methods.
      API has managed objects and data objects.
      Managed objects define methods, data objects do not.
    • 176. Surviving the vSphere API Documentation (cont)
      When calling managed object methods you will generally need to supply some data objects.
      Managed objects are returned by PowerCLI’s Get-View cmdlet.
      Data objects are constructed by PowerShell’s New-Object cmdlet.
      New-Object VMware.Vim.VirtualMachineConfigSpec
    • 177. Using “Project Onyx”.
      Onyx is a code generator.
      Sits between vSphere Client and vCenter.
      Any UI click is automatically turned to code.
    • 178. “Project Onyx” Architecture.
      ESX or vCenter
    • 179. API
      Using Onyx.
    • 180. 3 Takeaways: Onyx.
      Onyx makes it simple to understand what calls vSphere Client makes and when.
      From this you can understand the best practices and tested code paths VMware uses.
      Warning: You will need to re-factor code generated by Onyx.
    • 181. Advanced VM management topics.
      PowerCLI can run commands inside your guests.
      You can granularly control the placement of memory and snapshot files.
      Using View? PowerCLI gives you granular control over VM video memory.
    • 182. 2 ways to manage your guests.
      With PowerShell / PowerCLI you can manage inside your guest too.
      Option 1: WMI over the network.
      Option 2: Invoke-VMScript and related cmdlets via VMware Tools.
    • 183. VMs
      Guest management.
      Key cmdlets:
      • Invoke-VMScript
      • 184. Copy-GuestFile
    • 185. 3 Takeaways: Guest Management.
      Run programs in your guest or copy files there.
      You could combine these to install software agents, etc.
      Supports Windows or Linux.
      Works even if your VM’s network is down or disconnected.
    • 186. More advanced guest management: Customizing the scripts.
      Certain guest cmdlets can be completely re-wired by substituting their scripts.
      Script sources located at $env:PROGRAMFILESVMwareInfrastructurevSphere PowerCLIScripts
    • 187. VMs
      Changing swap and memory location.
      Key cmdlets:
      • Get-View
    • 188. 4 Takeaways: Changing swap location.
      Take advantage of cheaper storage for less critical data.
      Controllable on a per-cluster, per-host, or per-vm basis.
      Changes location for both snapshot and virtual memory.
      Warning: Decreases average reliability.
    • 189. Advanced storage management topics.
      All about iSCSI.
      Storage path reporting and management.
      Telling the difference between shared and unshared storage.
      Reporting on LUN performance.
      Configuring queue depth.
    • 190. Adding iSCSI datastores.
      Adding iSCSI to ESX is a good deal more complex.
      But it offers more options and security features.
      PowerCLI can add the storage with or without authentication.
    • 191. Storage
      Adding iSCSI to your hosts.
      Key cmdlets:
    • 194. 3 Takeaways: Using iSCSI.
      iSCSI comes in two flavors, software and hardware.
      To use software iSCSI you must enable the virtual iSCSI adapter.
      iSCSI has richer security capabilities than NFS. This leads to higher complexity.
      PowerCLI has very rich support for iSCSI.
    • 195. Two types of storage for your VMs.
      VMDK-based virtual hard disks.
      Raw devices (RDM).
      Warning: Think hard before using RDM!
      Won’t overcome size limitations!
      Won’t necessarily give you better performance!
    • 196. Storage
      Finding and mounting raw devices.
      Key cmdlets:
    • 198. 3 Takeaways: Raw Devices.
      Raw devices are necessary in some applications such as MSCS.
      PowerCLI makes it easy to mount, unmount and report on raw devices.
      Warning: If you don’t need raw devices you probably shouldn’t use them.
    • 199. Storage
      Find VMs on unshared storage.
      Key cmdlets:
    • 202. 3 Takeaways: Unshared VMs.
      VMs on unshared storage can’t participate in many advanced vSphere features such as DRS.
      If you’ve got hundreds or thousands of VMs you have to automate finding unshared VMs.
      PowerCLI also makes it easy to solve the problem: with Move-VM.
    • 203. Storage
      Determining LUN Performance.
      Key cmdlets:
      • Get-Stat
      • 204. Warning: Doesn’t work with NFS storage.
    • 205. 3 Takeaways: LUN Performance.
      LUN latency is a key statistic to watch. If it gets too high, workloads will be affected.
      There are no real standards but a pretty good suggestion is:
      Virtual desktops: Users will start complaining at about 20ms latency.
      Non-interactive, workloads: will be impacted around 40ms latency.
      Once you identify the problem, solve it
      with PowerCLI’s Move-VM.
    • 206. Configuring adapter queue depth.
      By default your adapter’s queue depth is 32.
      This can be adjusted.
      Warning: adjustments require host reboots.
      Warning: May increasing queue depth may worsen performance depending on your storage network and storage.
    • 207. Storage
      Configuring adapter queue depth.
      Key cmdlets:
      • Set-VMHostModule
    • 208. 3 Takeaways: Queue Depth.
      Increasing queue depth can improve your storage performance.
      It can also harm it, especially on LUNs shared by lots of hosts.
      Be sure to read and understand all factors in play before making any changes.
    • 209. Advanced network management.
      Advanced switch and portgroup policies.
      Creating and updating your service consoles.
    • 210. Network
      Advanced Network Management.
      Key cmdlets XXX need demo copied to desktop:
      • Get-NicTeamingPolicy
      • 211. Set-NicTeamingPolicy
    • 212. 3 Takeaways: Advanced Network Management.
      Policies can be set on a per-switch or per-portgroup basis.
      Switch policies are inherited by portgroups unless they are explicitly overridden.
      The right policy is critical to effective operation and high availability of your ESX hosts. PowerCLI helps you be consistent.
    • 213. Advanced ESX management.
      ESX build scripts.
      Setting advanced configuration parameters.
    • 214. ESX build scripts you can use.
      Lance Berc’s “How To Configure Freshly Booted ESX with PowerShell”
      Stephen’s Campbell’s “Not Another ESX Provisioning Script”
    • 215. ESX
      Advanced Host Options.
      Key cmdlets:
      • Set-VMHostAdvancedConfiguration
    • 216. 3 Takeaways: Advanced Host Options.
      There are hundreds of advanced host options.
      Some vendors (example NetApp) recommend specific settings for some options. PowerCLI ensures you can set and audit these consistently.
      Warning: advanced options regularly change between releases.
    • 217. ESX
      Key cmdlets:
      • Get-View
    • 218. 3 Takeaways: Licensing.
      Applying a license is a necessary step in any ESX build script.
      Licensing changed a lot for vSphere.
      Different calls are needed depending on if you are connected to ESX or vCenter.
    • 219. Advanced Reporting.
      Identifying performance bottlenecks.
      Searching and archiving log files.
      Mixing vSphere and Active Directory.
    • 220. Reports
      Identifying performance bottlenecks.
      Key cmdlets:
      • Get-Stat
    • 221. 3 Takeaways: Performance Bottlenecks.
      Bottlenecks occur when too many things compete for too few things.
      PowerCLI can identify resources that have too many competitors.
      PowerCLI can also easily move these around to balance workloads.
    • 222. Reports
      Archiving Log Files.
      Key cmdlets:
      • Copy-DatastoreItem
    • 223. 3 Takeaways: Archiving Log Files.
      Retaining log files is critical for audit and compliance.
      Log files are rotated (a.k.a. deleted) regularly.
      The number of log files retained is customizable through PowerCLI.
    • 224. 6 Advanced FAQs (with answers!)
      How can I reconfigure all my alarms to send SNMP traps?
      How to find and register missing VMs?
      How to report on RDM?
      How to change DNS servers for ESX?
      How do I schedule a PowerCLI script?
      How about a script to respond to an
    • 225. Tips
      Updating vCenter alarms.
      Key cmdlets:
      • Get-View
    • 226. 2 Takeaways: vCenter Alarms.
      If you’re deploying a lot of vCenter instances, PowerCLI will consistently reconfigure alarms just the way you want them.
      LucD has a great script to move alarms from one container to another.
    • 227. Tips
      Find and register missing VMs.
      Key cmdlets:
    • 230. 2 Takeaways: Registering VMs.
      Unregistering a VM rather than deleting it is a very common problem. This leads to wasted resources.
      Warning: If you have two vCenters sharing the same storage, you will get false positives!
    • 231. Tips
      Reporting on RDM.
      Key cmdlets:
    • 233. 1 Takeaway: RDM Reporting.
      This simple report will help you ensure RDM is only being used by VMs that need it.
    • 234. Tips
      Changing ESX IP address and DNS server.
      Key cmdlets:
      • Set-VMHostNetwork
      • 235. Set-VMHostNetworkAdapter
    • 236. 2 Takeaways: Changing ESX IP and DNS.
      Setting IP and DNS is another essential component of deploying ESX.
      The same PowerCLI command lets you set IP and DNS attributes.
    • 237. How to schedule PowerCLI scripts.
      Alan Renouf has a great writeup.
    • 238. 3 vSphere killers to regularly check.
      Are any VMs waiting for answers?
      Automatically scanning for configuration issues.
      DRS clusters with configuration problems.
    • 239. Running scripts in response to alarms.
      Fully documented 5 step process on the PowerCLI blog.
    • 240. Questions?
      Download today: