SlideShare une entreprise Scribd logo
1  sur  200
vSphere PowerCLI The best tool for automating vSphere http://vmware.com/go/powercli
Introduction. About me. Product Manager – APIs and platform. twitter.com/cshanklin (@cshanklin) Did you know? Most of the world’s top virtualization experts use twitter? http://vmware.com/go/powercli
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.” http://vmware.com/go/powercli
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. http://vmware.com/go/powercli
Financial analysis – then.
Financial analysis – now.
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. http://vmware.com/go/powercli
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. http://vmware.com/go/powercli
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. http://vmware.com/go/powercli
Overview / Agenda (cont). Other PowerCLI topics. Advanced: Intro to the API. Advanced Storage. Advanced Network. Advanced ESX. Other Advanced Topics. http://vmware.com/go/powercli
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? http://vmware.com/go/powercli
Getting to know you. Where are you wasting your time? Provisioning? Change management? Troubleshooting? What business pressures do you face? Supporting a wider variety of applications? Improving availability? Other things? http://vmware.com/go/powercli
Intro To PowerShell http://vmware.com/go/powercli
Top 5 things to know about PowerShell. The purpose. The cmdlets. The pipeline. The platforms. The products. http://vmware.com/go/powercli
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. http://vmware.com/go/powercli
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. http://vmware.com/go/powercli
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. Example: Get-Process notepad | Stop-Process Get-VM myvm | Start-VM http://vmware.com/go/powercli
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. http://vmware.com/go/powercli
PowerShell: The Products. PowerShell support is required for all Microsoft server applications. Exchange. Sharepoint. IIS. Many more. And, of course, VMware. http://vmware.com/go/powercli
The top 9 most used cmdlets.
The top 9 most used operators.
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”? http://vmware.com/go/powercli
Most Used PowerShell Cmdlets and Operators. Demo http://vmware.com/go/powercli
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. http://vmware.com/go/powercli
One bonus cmdlet you will need to automate! Import-CSV. Imports a spreadsheet. Great for doing anything at large scale. Learn this pattern and technique you won’t regret it! http://vmware.com/go/powercli
Using Import-CSV. Key cmdlets: ,[object Object]
Export-CSV
Get-ContentDemo http://vmware.com/go/powercli
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. http://vmware.com/go/powercli
5 PowerShell tools you should use. VESI (Virtualization EcoShell). PowerGUI. Virtu-Al.Net vSphere PowerPack. PowerShell WMI Explorer. PowerShell Plus. http://vmware.com/go/powercli
Intro To PowerCLI http://vmware.com/go/powercli
Top 5 things to know about PowerCLI. The purpose. The cmdlets. Cmdlet Tetris. The products. The future. http://vmware.com/go/powercli
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. http://vmware.com/go/powercli
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 	unnecessary. http://vmware.com/go/powercli
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. http://vmware.com/go/powercli
PowerCLI: The Products. vCenter: 2.5, 4.0 ESX / ESXi 3.0, 3.5, 4.0 VMware Update Manager (preview) http://vmware.com/go/powercli
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”) http://vmware.com/go/powercli
Making sense of it all.
Where do you feel the most pain? Configuring and maintaining ESX hosts? VMs? Reporting? Performance analysis? Troubleshooting? http://vmware.com/go/powercli
Use Cases and Demos http://vmware.com/go/powercli
PowerCLI Support Matrix (4.0 U1) (Latest) Tips Windows Vista (32 and 64 bit) Windows 2003 (32 and 64 bit) Windows XP http://vmware.com/go/powercli
PowerCLI Support Matrix (4.1) (Future!) Tips 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 http://vmware.com/go/powercli
3 ways to connect. Tips 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. See http://poshcode.org/501 http://vmware.com/go/powercli
Tips A 5-minute introduction to PowerCLI. Key cmdlets: ,[object Object]
Get-VMHost
Get-VMDemo http://vmware.com/go/powercli
3 Takeaways: 5 minute intro. Tips 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. http://vmware.com/go/powercli
Get-TheMost out of “Help” Tips 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” http://vmware.com/go/powercli
Get-TheMost out of “Get” cmdlets. Tips 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. Demo. http://vmware.com/go/powercli
PowerCLI supports multiple connections. Tips 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. Demo. http://vmware.com/go/powercli
The top 9 VM-related cmdlets. VMs
Managing VMs with PowerCLI. VMs Provisioning. Change / Update. Change its resource allocation (e.g. memory). Change its networking. Add/remove storage. VMware Tools. http://vmware.com/go/powercli
What challenges do you face around VMs? 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? http://vmware.com/go/powercli
3 ways to provision your VMs. VMs Creating blank VMs and PXE booting them. Clone a template. Clone a VM while running. http://vmware.com/go/powercli
VMs Provisioning at large scales. Key cmdlets: ,[object Object]
Get-Template
Get-OSCustomizationSpecDemo http://vmware.com/go/powercli
3 Takeaways: Large-scale provisioning. VMs 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. http://vmware.com/go/powercli
VMs Large-scale VM Updates. Key cmdlets: ,[object Object]
Set-VMDemo http://vmware.com/go/powercli
3 Takeaways: VM Updates. VMs 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. http://vmware.com/go/powercli
VMs Dealing with snapshots. Key cmdlets: ,[object Object]
Remove-Snapshot
Where-ObjectDemo http://vmware.com/go/powercli
3 Takeaways: Snapshots. VMs Snapshots are the “silent datastore killer”. Track their age and size with PowerCLI. Deleting lots of snapshots is a snap (sorry). http://vmware.com/go/powercli
The top 8 ESX-related cmdlets. ESX
Managing ESX with PowerCLI. ESX Provisioning (Host profiles or scripted) Change / Update. Storage. Network. Security, etc. Managing power and connection state. http://vmware.com/go/powercli
What challenges do you face deploying ESX? 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? http://vmware.com/go/powercli
2 ways to provision your ESX hosts. ESX 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. http://vmware.com/go/powercli
ESX Dealing with Host Profiles. Key cmdlets: ,[object Object]
Apply-VMHostProfile
Test-VMHostProfileComplianceDemo http://vmware.com/go/powercli
3 Takeaways: Host Profiles. ESX 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. http://vmware.com/go/powercli
Why we cluster. ESX 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. http://vmware.com/go/powercli
ESX Clustering your hosts for max availability. Key cmdlets: ,[object Object]
Set-Cluster
Move-VMHostDemo http://vmware.com/go/powercli
2 Takeaways: Clustering. ESX 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. http://vmware.com/go/powercli
You can also automate DRS rules. ESX Key cmdlets: New-DrsRule Get-DrsRule Set-DrsRule Remove-DrsRule http://vmware.com/go/powercli
The top 9 storage-related cmdlets. Storage
Managing Storage with PowerCLI. Storage Adding existing datastores or formatting new. Rescanning storage. Capacity and utilization reports. Identifying datastores that are not visible to the entire cluster. http://vmware.com/go/powercli
What challenges do you face around storage? 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? http://vmware.com/go/powercli
Storage VMotion is a snap. Storage Move-VM is a versatile command. If you use –Datastore you will Storage VMotion. http://vmware.com/go/powercli
Storage VMotion and Storage VMotion with Move-VM. Key cmdlets: ,[object Object]
Get-VMHost
Get-DatastoreDemo http://vmware.com/go/powercli
3 Takeaways: Storage VMotion. Storage 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 http://vmware.com/go/powercli
Save money with thin provisioning. Storage 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. http://vmware.com/go/powercli
Storage Thin Provisioning. Key cmdlets: ,[object Object]
New-Harddisk
Set-HarddiskDemo http://vmware.com/go/powercli
3 Takeaways: Thin Provisioning. Storage 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. http://vmware.com/go/powercli
Storage Adding NFS Datastores to ESX. Key cmdlets: ,[object Object],Demo http://vmware.com/go/powercli
2 Takeaways: NFS Datastores. Storage Adding and auditing NFS datastores is simple with PowerCLI. Warning: NFS performance statistics are not available (coming in a future version of vSphere). http://vmware.com/go/powercli
The top 9 network-related cmdlets. Network
Managing Networking with PowerCLI. Network Adding or configuring VMKernel. Moving VMs between virtual switches. Configuring virtual switch policies. http://vmware.com/go/powercli
What challenges do you face around network? 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? http://vmware.com/go/powercli
Network Moving VMs between networks. Key cmdlets: ,[object Object]
Set-NetworkAdapterDemo http://vmware.com/go/powercli
2 Takeaways: Changing VM Networks. Network 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. http://vmware.com/go/powercli
Network Configuring Consistent Virtual Switches. Key cmdlets: ,[object Object]
Get-VirtualSwitchDemo http://vmware.com/go/powercli
3 Takeaways: Virtual Switches. Network 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). http://vmware.com/go/powercli
The top 5 reporting cmdlets. Reports
Reporting with PowerCLI. Reports Three major categories of PowerCLI reports. Inventory-based reporting. Statistic-based reporting (i.e. performance) Event-based reporting. http://vmware.com/go/powercli
Reporting with PowerCLI. Reports 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”? http://vmware.com/go/powercli
Inventory-based reporting. Reports Relies on Get-* cmdlets as a starting point. Generally combined with Export-CSV or ConvertTo-Html. http://vmware.com/go/powercli
Report on your guest disk capacity. Reports Basic report. Sort by least % free space. Show all guests with <10% free space. http://vmware.com/go/powercli
Reports Reporting on Guest Disk Capacity. Key cmdlets: ,[object Object]
Get-HarddiskDemo http://vmware.com/go/powercli
3 Takeaways: Guest Disks. Reports 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. http://vmware.com/go/powercli
3 ways to report on wasted resources. Reports Orphaned VMDKs. – script not working now Unused VMs. ??? http://vmware.com/go/powercli
Reports Reporting on Wasted Resources. Key cmdlets: ,[object Object]
??Demo http://vmware.com/go/powercli
3 Takeaways: Wasted Resources. Reports X1 X2 X3 http://vmware.com/go/powercli
Reporting with custom attributes. Reports Custom attributes are extremely useful for tracking things unique to your deployment. Example: VM owner, app owner, etc. Get-CustomAttribute. http://vmware.com/go/powercli
Reports Reporting with Custom Attributes. Key cmdlets: ,[object Object]
Get-InventoryDemo http://vmware.com/go/powercli
3 Takeaways: Custom Attributes. Reports 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. http://vmware.com/go/powercli
Reports Security reporting using roles and permissions. Key cmdlets: ,[object Object]
Get-VIRoleDemo http://vmware.com/go/powercli
3 Takeaways: Roles and Permissions. Reports 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. http://vmware.com/go/powercli
Statistic-based reporting. Reports 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. http://vmware.com/go/powercli
Get-TheMost out of Get-Stat. Reports Get-StatType identifies available statistics. Understanding instances is critical. Note: vCenter and ESX may report different types of statistics. http://vmware.com/go/powercli
Reports Introduction to statistic-based reporting. Key cmdlets: ,[object Object],Demo http://vmware.com/go/powercli
3 Takeaways: Reporting with Statistics. Reports 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) http://vmware.com/go/powercli
Top 8 Most Interesting Statistics. Reports
Reports Most and least busy VMs and Hosts. Key cmdlets: ,[object Object],Demo http://vmware.com/go/powercli
2 Takeaways: Host and VM Usage. Reports 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. http://vmware.com/go/powercli
Event-based reporting. Reports 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. http://vmware.com/go/powercli
Reports Introduction to event-based reporting. Key cmdlets: ,[object Object],Demo http://vmware.com/go/powercli
3 Takeaways: Event-based reporting. Reports 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. http://vmware.com/go/powercli
Reports When was that VM powered on? Key cmdlets: ,[object Object],Demo http://vmware.com/go/powercli
3 Takeaways: Determining VM Poweron Date. Reports Just one of many reports you can do with events. Others: 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. http://vmware.com/go/powercli
You can get your VM’s log file too. Reports Get to know vmstore: Use Copy-DatastoreItem to bridge the gap between local and remote. http://vmware.com/go/powercli
This report will make your manager love you (in a completely legal way). Reports Alan Renouf’s Daily Report. Reports: 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! http://www.virtu-al.net/2009/11/04/vcheck-daily-report-v3/ http://vmware.com/go/powercli
Stuff Alan’s Daily Report Will Tell You. Reports 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) http://vmware.com/go/powercli
Sample Daily Report Output. Reports
The top 9 other cmdlets. Tips
Top 5 PowerCLI FAQs (With answers!) Tips 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? http://vmware.com/go/powercli
Top 5 PowerCLI FAQs (With answers!) Tips 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. http://vmware.com/go/powercli
Top 5 PowerCLI FAQs (With answers!) Tips 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. Demo. http://vmware.com/go/powercli
Top 5 PowerCLI FAQs (With answers!) Tips 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). Demo. http://vmware.com/go/powercli
Secure your scripts with these tips. Tips You can configure PowerShell to not run unsigned scripts. Set-ExecutionPolicyAllSigned PowerShell Plus has built-in script signing. http://vmware.com/go/powercli
3 mistakes you need to avoid! Tips 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 	Write-Output. http://vmware.com/go/powercli
4 tips to make your scripts more readable Tips 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. http://vmware.com/go/powercli
Tips Maximizing readability and maintainability. Demo http://vmware.com/go/powercli
3 Takeaways: Readability. Tips 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. http://vmware.com/go/powercli
Tips Speeding up your scripts. Demo http://vmware.com/go/powercli
3 Takeaways: Speeding up your scripts. Tips 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. http://vmware.com/go/powercli
1 feature you absolutely need to know. Tips 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” Demo. http://vmware.com/go/powercli
Tips Simplifying Reporting With Object Extensions. Key cmdlets: ,[object Object]
(Name subject to change)Demo (Future Features) http://vmware.com/go/powercli
3 Takeaways: Object Extensions. Tips 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. http://vmware.com/go/powercli
Learn to write a PowerShell Advanced Function Tips PowerShell Advanced Functions function almost exactly like PowerShell cmdlets. You can write scripts that: Sit in the PowerShell pipeline. Interoperate with all PowerCLI cmdlets. Demo. “help about_functions_advanced”. See “VI Toolkit Extensions” for samples. http://vmware.com/go/powercli
Learn to write a PowerShell Advanced Function Tips PowerShell Advanced Functions function almost exactly like PowerShell cmdlets. You can write scripts that: Sit in the PowerShell pipeline. Interoperate with all PowerCLI cmdlets. Demo. “help about_functions_advanced”. See “VI Toolkit Extensions” for samples. http://vmware.com/go/powercli
Anatomy of an advanced function. Tips functionAdvanced-Function { param(     [Parameter(Mandatory=$true,...]     [VMware.VimAutomation.Client20.VMHostImpl] $VMHost   ) 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)
Sample advanced function: ESX Host Routes. Tips Demo. http://vmware.com/go/powercli
Resources http://vmware.com/go/powercli
3 must-own resources: Tips Managing VMware Infrastructure with Windows PowerShell. vSphere 4.0 Quick Start Guide. VMware vSphere Pro Series Training. http://vmware.com/go/powercli
The “PowerCLI Bible” Tips http://vmware.com/go/powercli
Lots of PowerCLI Samples. Tips http://vmware.com/go/powercli
New training from TrainSignal! Tips
6 Amazing Blogs to Follow: Tips
The most important resource of all: Tips The PowerCLI Community. http://vmware.com/go/powercli More than 500 scripts. Search a huge and growing knowledgebase. Ask questions and get answers. http://vmware.com/go/powercli
By Sheer Coincidence. Tips PowerShell Master Class [3 dagar] Instructor: Thomas Lee, PowerShell MVP Begins 2010-03-09 http://www.labcenter.se/Lab/2056 http://vmware.com/go/powercli
Advanced Stuff! http://vmware.com/go/powercli
The vSphere API Stack. API
Managed objects and automation objects. API 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. http://vmware.com/go/powercli
Explore the vSphere API with PowerCLI. API 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 http://vmware.com/go/powercli
You can do anything with Get-View. API 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. http://vmware.com/go/powercli
API Use Get-View and Get-Member to explore the API. Key cmdlets: ,[object Object]
Get-MemberDemo http://vmware.com/go/powercli
4 Takeaways: Get-View. API 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: http://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/index.html http://vmware.com/go/powercli
Surviving the vSphere API Documentation. API 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. http://vmware.com/go/powercli
Surviving the vSphere API Documentation (cont) API 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
Using “Project Onyx”. API Onyx is a code generator. Sits between vSphere Client and vCenter. Any UI click is automatically turned to code. http://vmware.com/go/powercli
“Project Onyx” Architecture. API ESX or vCenter
API Using Onyx. Demo http://vmware.com/go/powercli
3 Takeaways: Onyx. API 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. http://vmware.com/go/powercli
Advanced VM management topics. VMs 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. http://vmware.com/go/powercli
2 ways to manage your guests. VMs 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. http://vmware.com/go/powercli
VMs Guest management. Key cmdlets: ,[object Object]
Copy-GuestFileDemo http://vmware.com/go/powercli
3 Takeaways: Guest Management. VMs 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. http://vmware.com/go/powercli
More advanced guest management: Customizing the scripts. VMs Certain guest cmdlets can be completely re-wired by substituting their scripts. Script sources located at $env:PROGRAMFILESMwarenfrastructureSphere PowerCLIcripts http://vmware.com/go/powercli
VMs Changing swap and memory location. Key cmdlets: ,[object Object],Demo http://vmware.com/go/powercli
4 Takeaways: Changing swap location. VMs 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. http://vmware.com/go/powercli
Advanced storage management topics. Storage All about iSCSI. Storage path reporting and management. Telling the difference between shared and unshared storage. Reporting on LUN performance. Configuring queue depth. http://vmware.com/go/powercli
Adding iSCSI datastores. Storage 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. http://vmware.com/go/powercli
Storage Adding iSCSI to your hosts. Key cmdlets: ,[object Object]
Get-ScsiLun
New-DatastoreDemo http://vmware.com/go/powercli
3 Takeaways: Using iSCSI. Storage 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. http://vmware.com/go/powercli
Two types of storage for your VMs. Storage 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! http://vmware.com/go/powercli
Storage Finding and mounting raw devices. Key cmdlets: ,[object Object]
New-HarddiskDemo http://vmware.com/go/powercli
3 Takeaways: Raw Devices. Storage 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. http://vmware.com/go/powercli
Storage Find VMs on unshared storage. Key cmdlets: ,[object Object]
Get-Datastore

Contenu connexe

Similaire à PowerCLI Workshop

Managing VMware with PowerShell - VMworld 2008
Managing VMware with PowerShell - VMworld 2008Managing VMware with PowerShell - VMworld 2008
Managing VMware with PowerShell - VMworld 2008Carter Shanklin
 
VMworld 2015: Day to Day Automation of VMware Products to Increase Productivi...
VMworld 2015: Day to Day Automation of VMware Products to Increase Productivi...VMworld 2015: Day to Day Automation of VMware Products to Increase Productivi...
VMworld 2015: Day to Day Automation of VMware Products to Increase Productivi...VMworld
 
PowerShell Scripting and AI-infused Automation
PowerShell Scripting and AI-infused AutomationPowerShell Scripting and AI-infused Automation
PowerShell Scripting and AI-infused AutomationMitul Rana
 
Automating the VMware Virtual Datacenter
Automating the VMware Virtual DatacenterAutomating the VMware Virtual Datacenter
Automating the VMware Virtual DatacenterJosh Atwell
 
VMworld 2013: Automating the Software Defined Data Center: How Do I Get Started
VMworld 2013: Automating the Software Defined Data Center: How Do I Get Started VMworld 2013: Automating the Software Defined Data Center: How Do I Get Started
VMworld 2013: Automating the Software Defined Data Center: How Do I Get Started VMworld
 
VMworld 2013: PowerCLI Best Practices - A Deep Dive
VMworld 2013: PowerCLI Best Practices - A Deep DiveVMworld 2013: PowerCLI Best Practices - A Deep Dive
VMworld 2013: PowerCLI Best Practices - A Deep DiveVMworld
 
Say Bye to VMware PowerCLI ! Time to "GOVC"
Say Bye to VMware PowerCLI ! Time to "GOVC"Say Bye to VMware PowerCLI ! Time to "GOVC"
Say Bye to VMware PowerCLI ! Time to "GOVC"Ajeet Singh Raina
 
Sql Server & PowerShell
Sql Server & PowerShellSql Server & PowerShell
Sql Server & PowerShellAaron Shilo
 
VMware Automation, PowerCLI presented at the Northern California PSUG
VMware Automation, PowerCLI presented at the Northern California PSUGVMware Automation, PowerCLI presented at the Northern California PSUG
VMware Automation, PowerCLI presented at the Northern California PSUGAlan Renouf
 
Dutch VMUG 2010 PowerCLI Presentation
Dutch VMUG 2010 PowerCLI PresentationDutch VMUG 2010 PowerCLI Presentation
Dutch VMUG 2010 PowerCLI PresentationAlan Renouf
 
VMworld 2016: Getting Started with PowerShell and PowerCLI for Your VMware En...
VMworld 2016: Getting Started with PowerShell and PowerCLI for Your VMware En...VMworld 2016: Getting Started with PowerShell and PowerCLI for Your VMware En...
VMworld 2016: Getting Started with PowerShell and PowerCLI for Your VMware En...VMworld
 
Inventory your network and clients with PowerShell
Inventory your network and clients with PowerShellInventory your network and clients with PowerShell
Inventory your network and clients with PowerShellConcentrated Technology
 
Managing Virtual Infrastructures With PowerShell
Managing Virtual Infrastructures With PowerShellManaging Virtual Infrastructures With PowerShell
Managing Virtual Infrastructures With PowerShellguesta849bc8b
 
Save Time With PowerCLI
Save Time With PowerCLISave Time With PowerCLI
Save Time With PowerCLIjonathanmedd
 
Managing V Sphere With The Vesi
Managing V Sphere With The VesiManaging V Sphere With The Vesi
Managing V Sphere With The VesiEric Sloof
 
Www.vmware.com support developer_windowstoolkit_wintk10_doc_viwin_admin
Www.vmware.com support developer_windowstoolkit_wintk10_doc_viwin_adminWww.vmware.com support developer_windowstoolkit_wintk10_doc_viwin_admin
Www.vmware.com support developer_windowstoolkit_wintk10_doc_viwin_adminVenkata Ramana
 
PowerShell in the enterprise - TechED India 2011
PowerShell in the enterprise - TechED India 2011PowerShell in the enterprise - TechED India 2011
PowerShell in the enterprise - TechED India 2011Ravikanth Chaganti
 
MVVM+MEF in Silvelight - W 2010ebday
MVVM+MEF in Silvelight - W 2010ebdayMVVM+MEF in Silvelight - W 2010ebday
MVVM+MEF in Silvelight - W 2010ebdayRicardo Fiel
 
Containerizing legacy applications
Containerizing legacy applicationsContainerizing legacy applications
Containerizing legacy applicationsAndrew Kirkpatrick
 

Similaire à PowerCLI Workshop (20)

San Diego VMUG Oct 2009
San Diego VMUG Oct 2009San Diego VMUG Oct 2009
San Diego VMUG Oct 2009
 
Managing VMware with PowerShell - VMworld 2008
Managing VMware with PowerShell - VMworld 2008Managing VMware with PowerShell - VMworld 2008
Managing VMware with PowerShell - VMworld 2008
 
VMworld 2015: Day to Day Automation of VMware Products to Increase Productivi...
VMworld 2015: Day to Day Automation of VMware Products to Increase Productivi...VMworld 2015: Day to Day Automation of VMware Products to Increase Productivi...
VMworld 2015: Day to Day Automation of VMware Products to Increase Productivi...
 
PowerShell Scripting and AI-infused Automation
PowerShell Scripting and AI-infused AutomationPowerShell Scripting and AI-infused Automation
PowerShell Scripting and AI-infused Automation
 
Automating the VMware Virtual Datacenter
Automating the VMware Virtual DatacenterAutomating the VMware Virtual Datacenter
Automating the VMware Virtual Datacenter
 
VMworld 2013: Automating the Software Defined Data Center: How Do I Get Started
VMworld 2013: Automating the Software Defined Data Center: How Do I Get Started VMworld 2013: Automating the Software Defined Data Center: How Do I Get Started
VMworld 2013: Automating the Software Defined Data Center: How Do I Get Started
 
VMworld 2013: PowerCLI Best Practices - A Deep Dive
VMworld 2013: PowerCLI Best Practices - A Deep DiveVMworld 2013: PowerCLI Best Practices - A Deep Dive
VMworld 2013: PowerCLI Best Practices - A Deep Dive
 
Say Bye to VMware PowerCLI ! Time to "GOVC"
Say Bye to VMware PowerCLI ! Time to "GOVC"Say Bye to VMware PowerCLI ! Time to "GOVC"
Say Bye to VMware PowerCLI ! Time to "GOVC"
 
Sql Server & PowerShell
Sql Server & PowerShellSql Server & PowerShell
Sql Server & PowerShell
 
VMware Automation, PowerCLI presented at the Northern California PSUG
VMware Automation, PowerCLI presented at the Northern California PSUGVMware Automation, PowerCLI presented at the Northern California PSUG
VMware Automation, PowerCLI presented at the Northern California PSUG
 
Dutch VMUG 2010 PowerCLI Presentation
Dutch VMUG 2010 PowerCLI PresentationDutch VMUG 2010 PowerCLI Presentation
Dutch VMUG 2010 PowerCLI Presentation
 
VMworld 2016: Getting Started with PowerShell and PowerCLI for Your VMware En...
VMworld 2016: Getting Started with PowerShell and PowerCLI for Your VMware En...VMworld 2016: Getting Started with PowerShell and PowerCLI for Your VMware En...
VMworld 2016: Getting Started with PowerShell and PowerCLI for Your VMware En...
 
Inventory your network and clients with PowerShell
Inventory your network and clients with PowerShellInventory your network and clients with PowerShell
Inventory your network and clients with PowerShell
 
Managing Virtual Infrastructures With PowerShell
Managing Virtual Infrastructures With PowerShellManaging Virtual Infrastructures With PowerShell
Managing Virtual Infrastructures With PowerShell
 
Save Time With PowerCLI
Save Time With PowerCLISave Time With PowerCLI
Save Time With PowerCLI
 
Managing V Sphere With The Vesi
Managing V Sphere With The VesiManaging V Sphere With The Vesi
Managing V Sphere With The Vesi
 
Www.vmware.com support developer_windowstoolkit_wintk10_doc_viwin_admin
Www.vmware.com support developer_windowstoolkit_wintk10_doc_viwin_adminWww.vmware.com support developer_windowstoolkit_wintk10_doc_viwin_admin
Www.vmware.com support developer_windowstoolkit_wintk10_doc_viwin_admin
 
PowerShell in the enterprise - TechED India 2011
PowerShell in the enterprise - TechED India 2011PowerShell in the enterprise - TechED India 2011
PowerShell in the enterprise - TechED India 2011
 
MVVM+MEF in Silvelight - W 2010ebday
MVVM+MEF in Silvelight - W 2010ebdayMVVM+MEF in Silvelight - W 2010ebday
MVVM+MEF in Silvelight - W 2010ebday
 
Containerizing legacy applications
Containerizing legacy applicationsContainerizing legacy applications
Containerizing legacy applications
 

Plus de Carter Shanklin

Virtualizing Latency Sensitive Workloads and vFabric GemFire
Virtualizing Latency Sensitive Workloads and vFabric GemFireVirtualizing Latency Sensitive Workloads and vFabric GemFire
Virtualizing Latency Sensitive Workloads and vFabric GemFireCarter Shanklin
 
SQLFire at VMworld Europe 2011
SQLFire at VMworld Europe 2011SQLFire at VMworld Europe 2011
SQLFire at VMworld Europe 2011Carter Shanklin
 
June 2009 PowerCLI Webinar
June 2009 PowerCLI WebinarJune 2009 PowerCLI Webinar
June 2009 PowerCLI WebinarCarter Shanklin
 

Plus de Carter Shanklin (6)

SQLFire lightning talk
SQLFire lightning talkSQLFire lightning talk
SQLFire lightning talk
 
SQLFire at Strata 2012
SQLFire at Strata 2012SQLFire at Strata 2012
SQLFire at Strata 2012
 
Virtualizing Latency Sensitive Workloads and vFabric GemFire
Virtualizing Latency Sensitive Workloads and vFabric GemFireVirtualizing Latency Sensitive Workloads and vFabric GemFire
Virtualizing Latency Sensitive Workloads and vFabric GemFire
 
SQLFire Webinar
SQLFire WebinarSQLFire Webinar
SQLFire Webinar
 
SQLFire at VMworld Europe 2011
SQLFire at VMworld Europe 2011SQLFire at VMworld Europe 2011
SQLFire at VMworld Europe 2011
 
June 2009 PowerCLI Webinar
June 2009 PowerCLI WebinarJune 2009 PowerCLI Webinar
June 2009 PowerCLI Webinar
 

Dernier

A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024TopCSSGallery
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxfnnc6jmgwh
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesManik S Magar
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observabilityitnewsafrica
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesBernd Ruecker
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 

Dernier (20)

A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architectures
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 

PowerCLI Workshop

  • 1. vSphere PowerCLI The best tool for automating vSphere http://vmware.com/go/powercli
  • 2. Introduction. About me. Product Manager – APIs and platform. twitter.com/cshanklin (@cshanklin) Did you know? Most of the world’s top virtualization experts use twitter? http://vmware.com/go/powercli
  • 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.” http://vmware.com/go/powercli
  • 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. http://vmware.com/go/powercli
  • 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. http://vmware.com/go/powercli
  • 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. http://vmware.com/go/powercli
  • 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. http://vmware.com/go/powercli
  • 10. Overview / Agenda (cont). Other PowerCLI topics. Advanced: Intro to the API. Advanced Storage. Advanced Network. Advanced ESX. Other Advanced Topics. http://vmware.com/go/powercli
  • 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? http://vmware.com/go/powercli
  • 12. Getting to know you. Where are you wasting your time? Provisioning? Change management? Troubleshooting? What business pressures do you face? Supporting a wider variety of applications? Improving availability? Other things? http://vmware.com/go/powercli
  • 13. Intro To PowerShell http://vmware.com/go/powercli
  • 14. Top 5 things to know about PowerShell. The purpose. The cmdlets. The pipeline. The platforms. The products. http://vmware.com/go/powercli
  • 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. http://vmware.com/go/powercli
  • 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. http://vmware.com/go/powercli
  • 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. Example: Get-Process notepad | Stop-Process Get-VM myvm | Start-VM http://vmware.com/go/powercli
  • 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. http://vmware.com/go/powercli
  • 19. PowerShell: The Products. PowerShell support is required for all Microsoft server applications. Exchange. Sharepoint. IIS. Many more. And, of course, VMware. http://vmware.com/go/powercli
  • 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”? http://vmware.com/go/powercli
  • 23. Most Used PowerShell Cmdlets and Operators. Demo http://vmware.com/go/powercli
  • 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. http://vmware.com/go/powercli
  • 25. One bonus cmdlet you will need to automate! Import-CSV. Imports a spreadsheet. Great for doing anything at large scale. Learn this pattern and technique you won’t regret it! http://vmware.com/go/powercli
  • 26.
  • 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. http://vmware.com/go/powercli
  • 30. 5 PowerShell tools you should use. VESI (Virtualization EcoShell). PowerGUI. Virtu-Al.Net vSphere PowerPack. PowerShell WMI Explorer. PowerShell Plus. http://vmware.com/go/powercli
  • 31. Intro To PowerCLI http://vmware.com/go/powercli
  • 32. Top 5 things to know about PowerCLI. The purpose. The cmdlets. Cmdlet Tetris. The products. The future. http://vmware.com/go/powercli
  • 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. http://vmware.com/go/powercli
  • 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 unnecessary. http://vmware.com/go/powercli
  • 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. http://vmware.com/go/powercli
  • 36. PowerCLI: The Products. vCenter: 2.5, 4.0 ESX / ESXi 3.0, 3.5, 4.0 VMware Update Manager (preview) http://vmware.com/go/powercli
  • 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”) http://vmware.com/go/powercli
  • 38. Making sense of it all.
  • 39. Where do you feel the most pain? Configuring and maintaining ESX hosts? VMs? Reporting? Performance analysis? Troubleshooting? http://vmware.com/go/powercli
  • 40. Use Cases and Demos http://vmware.com/go/powercli
  • 41. PowerCLI Support Matrix (4.0 U1) (Latest) Tips Windows Vista (32 and 64 bit) Windows 2003 (32 and 64 bit) Windows XP http://vmware.com/go/powercli
  • 42. PowerCLI Support Matrix (4.1) (Future!) Tips 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 http://vmware.com/go/powercli
  • 43. 3 ways to connect. Tips 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. See http://poshcode.org/501 http://vmware.com/go/powercli
  • 44.
  • 47. 3 Takeaways: 5 minute intro. Tips 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. http://vmware.com/go/powercli
  • 48. Get-TheMost out of “Help” Tips 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” http://vmware.com/go/powercli
  • 49. Get-TheMost out of “Get” cmdlets. Tips 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. Demo. http://vmware.com/go/powercli
  • 50. PowerCLI supports multiple connections. Tips 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. Demo. http://vmware.com/go/powercli
  • 51. The top 9 VM-related cmdlets. VMs
  • 52. Managing VMs with PowerCLI. VMs Provisioning. Change / Update. Change its resource allocation (e.g. memory). Change its networking. Add/remove storage. VMware Tools. http://vmware.com/go/powercli
  • 53. What challenges do you face around VMs? 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? http://vmware.com/go/powercli
  • 54. 3 ways to provision your VMs. VMs Creating blank VMs and PXE booting them. Clone a template. Clone a VM while running. http://vmware.com/go/powercli
  • 55.
  • 58. 3 Takeaways: Large-scale provisioning. VMs 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. http://vmware.com/go/powercli
  • 59.
  • 61. 3 Takeaways: VM Updates. VMs 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. http://vmware.com/go/powercli
  • 62.
  • 65. 3 Takeaways: Snapshots. VMs Snapshots are the “silent datastore killer”. Track their age and size with PowerCLI. Deleting lots of snapshots is a snap (sorry). http://vmware.com/go/powercli
  • 66. The top 8 ESX-related cmdlets. ESX
  • 67. Managing ESX with PowerCLI. ESX Provisioning (Host profiles or scripted) Change / Update. Storage. Network. Security, etc. Managing power and connection state. http://vmware.com/go/powercli
  • 68. What challenges do you face deploying ESX? 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? http://vmware.com/go/powercli
  • 69. 2 ways to provision your ESX hosts. ESX 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. http://vmware.com/go/powercli
  • 70.
  • 73. 3 Takeaways: Host Profiles. ESX 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. http://vmware.com/go/powercli
  • 74. Why we cluster. ESX 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. http://vmware.com/go/powercli
  • 75.
  • 78. 2 Takeaways: Clustering. ESX 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. http://vmware.com/go/powercli
  • 79. You can also automate DRS rules. ESX Key cmdlets: New-DrsRule Get-DrsRule Set-DrsRule Remove-DrsRule http://vmware.com/go/powercli
  • 80. The top 9 storage-related cmdlets. Storage
  • 81. Managing Storage with PowerCLI. Storage Adding existing datastores or formatting new. Rescanning storage. Capacity and utilization reports. Identifying datastores that are not visible to the entire cluster. http://vmware.com/go/powercli
  • 82. What challenges do you face around storage? 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? http://vmware.com/go/powercli
  • 83. Storage VMotion is a snap. Storage Move-VM is a versatile command. If you use –Datastore you will Storage VMotion. http://vmware.com/go/powercli
  • 84.
  • 87. 3 Takeaways: Storage VMotion. Storage 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 http://vmware.com/go/powercli
  • 88. Save money with thin provisioning. Storage 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. http://vmware.com/go/powercli
  • 89.
  • 92. 3 Takeaways: Thin Provisioning. Storage 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. http://vmware.com/go/powercli
  • 93.
  • 94. 2 Takeaways: NFS Datastores. Storage Adding and auditing NFS datastores is simple with PowerCLI. Warning: NFS performance statistics are not available (coming in a future version of vSphere). http://vmware.com/go/powercli
  • 95. The top 9 network-related cmdlets. Network
  • 96. Managing Networking with PowerCLI. Network Adding or configuring VMKernel. Moving VMs between virtual switches. Configuring virtual switch policies. http://vmware.com/go/powercli
  • 97. What challenges do you face around network? 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? http://vmware.com/go/powercli
  • 98.
  • 100. 2 Takeaways: Changing VM Networks. Network 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. http://vmware.com/go/powercli
  • 101.
  • 103. 3 Takeaways: Virtual Switches. Network 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). http://vmware.com/go/powercli
  • 104. The top 5 reporting cmdlets. Reports
  • 105. Reporting with PowerCLI. Reports Three major categories of PowerCLI reports. Inventory-based reporting. Statistic-based reporting (i.e. performance) Event-based reporting. http://vmware.com/go/powercli
  • 106. Reporting with PowerCLI. Reports 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”? http://vmware.com/go/powercli
  • 107. Inventory-based reporting. Reports Relies on Get-* cmdlets as a starting point. Generally combined with Export-CSV or ConvertTo-Html. http://vmware.com/go/powercli
  • 108. Report on your guest disk capacity. Reports Basic report. Sort by least % free space. Show all guests with <10% free space. http://vmware.com/go/powercli
  • 109.
  • 111. 3 Takeaways: Guest Disks. Reports 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. http://vmware.com/go/powercli
  • 112. 3 ways to report on wasted resources. Reports Orphaned VMDKs. – script not working now Unused VMs. ??? http://vmware.com/go/powercli
  • 113.
  • 115. 3 Takeaways: Wasted Resources. Reports X1 X2 X3 http://vmware.com/go/powercli
  • 116. Reporting with custom attributes. Reports Custom attributes are extremely useful for tracking things unique to your deployment. Example: VM owner, app owner, etc. Get-CustomAttribute. http://vmware.com/go/powercli
  • 117.
  • 119. 3 Takeaways: Custom Attributes. Reports 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. http://vmware.com/go/powercli
  • 120.
  • 122. 3 Takeaways: Roles and Permissions. Reports 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. http://vmware.com/go/powercli
  • 123. Statistic-based reporting. Reports 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. http://vmware.com/go/powercli
  • 124. Get-TheMost out of Get-Stat. Reports Get-StatType identifies available statistics. Understanding instances is critical. Note: vCenter and ESX may report different types of statistics. http://vmware.com/go/powercli
  • 125.
  • 126. 3 Takeaways: Reporting with Statistics. Reports 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) http://vmware.com/go/powercli
  • 127. Top 8 Most Interesting Statistics. Reports
  • 128.
  • 129. 2 Takeaways: Host and VM Usage. Reports 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. http://vmware.com/go/powercli
  • 130. Event-based reporting. Reports 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. http://vmware.com/go/powercli
  • 131.
  • 132. 3 Takeaways: Event-based reporting. Reports 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. http://vmware.com/go/powercli
  • 133.
  • 134. 3 Takeaways: Determining VM Poweron Date. Reports Just one of many reports you can do with events. Others: 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. http://vmware.com/go/powercli
  • 135. You can get your VM’s log file too. Reports Get to know vmstore: Use Copy-DatastoreItem to bridge the gap between local and remote. http://vmware.com/go/powercli
  • 136. This report will make your manager love you (in a completely legal way). Reports Alan Renouf’s Daily Report. Reports: 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! http://www.virtu-al.net/2009/11/04/vcheck-daily-report-v3/ http://vmware.com/go/powercli
  • 137. Stuff Alan’s Daily Report Will Tell You. Reports 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) http://vmware.com/go/powercli
  • 138. Sample Daily Report Output. Reports
  • 139. The top 9 other cmdlets. Tips
  • 140. Top 5 PowerCLI FAQs (With answers!) Tips 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? http://vmware.com/go/powercli
  • 141. Top 5 PowerCLI FAQs (With answers!) Tips 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. http://vmware.com/go/powercli
  • 142. Top 5 PowerCLI FAQs (With answers!) Tips 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. Demo. http://vmware.com/go/powercli
  • 143. Top 5 PowerCLI FAQs (With answers!) Tips 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). Demo. http://vmware.com/go/powercli
  • 144. Secure your scripts with these tips. Tips You can configure PowerShell to not run unsigned scripts. Set-ExecutionPolicyAllSigned PowerShell Plus has built-in script signing. http://vmware.com/go/powercli
  • 145. 3 mistakes you need to avoid! Tips 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 Write-Output. http://vmware.com/go/powercli
  • 146. 4 tips to make your scripts more readable Tips 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. http://vmware.com/go/powercli
  • 147. Tips Maximizing readability and maintainability. Demo http://vmware.com/go/powercli
  • 148. 3 Takeaways: Readability. Tips 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. http://vmware.com/go/powercli
  • 149. Tips Speeding up your scripts. Demo http://vmware.com/go/powercli
  • 150. 3 Takeaways: Speeding up your scripts. Tips 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. http://vmware.com/go/powercli
  • 151. 1 feature you absolutely need to know. Tips 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” Demo. http://vmware.com/go/powercli
  • 152.
  • 153. (Name subject to change)Demo (Future Features) http://vmware.com/go/powercli
  • 154. 3 Takeaways: Object Extensions. Tips 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. http://vmware.com/go/powercli
  • 155. Learn to write a PowerShell Advanced Function Tips PowerShell Advanced Functions function almost exactly like PowerShell cmdlets. You can write scripts that: Sit in the PowerShell pipeline. Interoperate with all PowerCLI cmdlets. Demo. “help about_functions_advanced”. See “VI Toolkit Extensions” for samples. http://vmware.com/go/powercli
  • 156. Learn to write a PowerShell Advanced Function Tips PowerShell Advanced Functions function almost exactly like PowerShell cmdlets. You can write scripts that: Sit in the PowerShell pipeline. Interoperate with all PowerCLI cmdlets. Demo. “help about_functions_advanced”. See “VI Toolkit Extensions” for samples. http://vmware.com/go/powercli
  • 157. Anatomy of an advanced function. Tips functionAdvanced-Function { param( [Parameter(Mandatory=$true,...] [VMware.VimAutomation.Client20.VMHostImpl] $VMHost ) 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. Tips Demo. http://vmware.com/go/powercli
  • 160. 3 must-own resources: Tips Managing VMware Infrastructure with Windows PowerShell. vSphere 4.0 Quick Start Guide. VMware vSphere Pro Series Training. http://vmware.com/go/powercli
  • 161. The “PowerCLI Bible” Tips http://vmware.com/go/powercli
  • 162. Lots of PowerCLI Samples. Tips http://vmware.com/go/powercli
  • 163. New training from TrainSignal! Tips
  • 164. 6 Amazing Blogs to Follow: Tips
  • 165. The most important resource of all: Tips The PowerCLI Community. http://vmware.com/go/powercli More than 500 scripts. Search a huge and growing knowledgebase. Ask questions and get answers. http://vmware.com/go/powercli
  • 166. By Sheer Coincidence. Tips PowerShell Master Class [3 dagar] Instructor: Thomas Lee, PowerShell MVP Begins 2010-03-09 http://www.labcenter.se/Lab/2056 http://vmware.com/go/powercli
  • 168. The vSphere API Stack. API
  • 169. Managed objects and automation objects. API 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. http://vmware.com/go/powercli
  • 170. Explore the vSphere API with PowerCLI. API 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 http://vmware.com/go/powercli
  • 171. You can do anything with Get-View. API 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. http://vmware.com/go/powercli
  • 172.
  • 174. 4 Takeaways: Get-View. API 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: http://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/index.html http://vmware.com/go/powercli
  • 175. Surviving the vSphere API Documentation. API 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. http://vmware.com/go/powercli
  • 176. Surviving the vSphere API Documentation (cont) API 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”. API Onyx is a code generator. Sits between vSphere Client and vCenter. Any UI click is automatically turned to code. http://vmware.com/go/powercli
  • 178. “Project Onyx” Architecture. API ESX or vCenter
  • 179. API Using Onyx. Demo http://vmware.com/go/powercli
  • 180. 3 Takeaways: Onyx. API 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. http://vmware.com/go/powercli
  • 181. Advanced VM management topics. VMs 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. http://vmware.com/go/powercli
  • 182. 2 ways to manage your guests. VMs 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. http://vmware.com/go/powercli
  • 183.
  • 185. 3 Takeaways: Guest Management. VMs 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. http://vmware.com/go/powercli
  • 186. More advanced guest management: Customizing the scripts. VMs Certain guest cmdlets can be completely re-wired by substituting their scripts. Script sources located at $env:PROGRAMFILESMwarenfrastructureSphere PowerCLIcripts http://vmware.com/go/powercli
  • 187.
  • 188. 4 Takeaways: Changing swap location. VMs 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. http://vmware.com/go/powercli
  • 189. Advanced storage management topics. Storage All about iSCSI. Storage path reporting and management. Telling the difference between shared and unshared storage. Reporting on LUN performance. Configuring queue depth. http://vmware.com/go/powercli
  • 190. Adding iSCSI datastores. Storage 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. http://vmware.com/go/powercli
  • 191.
  • 194. 3 Takeaways: Using iSCSI. Storage 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. http://vmware.com/go/powercli
  • 195. Two types of storage for your VMs. Storage 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! http://vmware.com/go/powercli
  • 196.
  • 198. 3 Takeaways: Raw Devices. Storage 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. http://vmware.com/go/powercli
  • 199.
  • 202. 3 Takeaways: Unshared VMs. Storage 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. http://vmware.com/go/powercli
  • 203.
  • 204. Warning: Doesn’t work with NFS storage.Demo http://vmware.com/go/powercli
  • 205. 3 Takeaways: LUN Performance. Storage 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. http://vmware.com/go/powercli
  • 206. Configuring adapter queue depth. Storage 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. http://frankdenneman.wordpress.com/2009/03/04/increasing-the-queue-depth/ http://vmware.com/go/powercli
  • 207.
  • 208. 3 Takeaways: Queue Depth. Storage 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. http://vmware.com/go/powercli
  • 209. Advanced network management. Network Advanced switch and portgroup policies. Creating and updating your service consoles. http://vmware.com/go/powercli
  • 210.
  • 212. 3 Takeaways: Advanced Network Management. Network 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. http://vmware.com/go/powercli
  • 213. Advanced ESX management. ESX ESX build scripts. Setting advanced configuration parameters. Licensing. http://vmware.com/go/powercli
  • 214. ESX build scripts you can use. ESX Lance Berc’s “How To Configure Freshly Booted ESX with PowerShell” http://communities.vmware.com/thread/161304 Stephen’s Campbell’s “Not Another ESX Provisioning Script” http://communities.vmware.com/docs/DOC-8170 http://vmware.com/go/powercli
  • 215.
  • 216. 3 Takeaways: Advanced Host Options. ESX 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. http://vmware.com/go/powercli
  • 217.
  • 218. 3 Takeaways: Licensing. ESX 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. http://vmware.com/go/powercli
  • 219. Advanced Reporting. Reports Identifying performance bottlenecks. Searching and archiving log files. Mixing vSphere and Active Directory. http://vmware.com/go/powercli
  • 220.
  • 221. 3 Takeaways: Performance Bottlenecks. Reports 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. http://vmware.com/go/powercli
  • 222.
  • 223. 3 Takeaways: Archiving Log Files. Reports 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. http://vmware.com/go/powercli
  • 224. 6 Advanced FAQs (with answers!) Tips 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 alarm? http://vmware.com/go/powercli
  • 225.
  • 226. 2 Takeaways: vCenter Alarms. Tips 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. http://lucd.info/?p=1799 http://vmware.com/go/powercli
  • 227.
  • 230. 2 Takeaways: Registering VMs. Tips 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! http://vmware.com/go/powercli
  • 231.
  • 233. 1 Takeaway: RDM Reporting. Tips This simple report will help you ensure RDM is only being used by VMs that need it. http://vmware.com/go/powercli
  • 234.
  • 236. 2 Takeaways: Changing ESX IP and DNS. Tips Setting IP and DNS is another essential component of deploying ESX. The same PowerCLI command lets you set IP and DNS attributes. http://vmware.com/go/powercli
  • 237. How to schedule PowerCLI scripts. Tips Alan Renouf has a great writeup. http://www.virtu-al.net/2009/07/10/running-a-powercli-scheduled-task/ http://vmware.com/go/powercli
  • 238. 3 vSphere killers to regularly check. Tips Are any VMs waiting for answers? Automatically scanning for configuration issues. DRS clusters with configuration problems. http://vmware.com/go/powercli
  • 239. Running scripts in response to alarms. Tips Fully documented 5 step process on the PowerCLI blog. http://blogs.vmware.com/vipowershell/2009/09/how-to-run-powercli-scripts-from-vcenter-alarms.html http://vmware.com/go/powercli
  • 240. Questions? Download today: http://vmware.com/go/powercli http://vmware.com/go/powercli

Notes de l'éditeur

  1. 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.
  2. 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.
  3. Demo Script: MostUsedCmdlets.ps1
  4. Demo Script: ImportCSV.ps1
  5. Demo Script: 5Minute.ps1
  6. Demo Script: LargeProvisioning.ps1
  7. Demo Script: LargeUpdate.ps1
  8. Demo Script: Snapshots.ps1
  9. Demo Script: HostProfiles.ps1
  10. Demo Script: Clusters.ps1
  11. Demo Script: VMotionStorageVMotion.ps1
  12. Demo Script: ThinProvision.ps1
  13. Demo Script: NFS.ps1
  14. Demo Script: MoveVMNetwork.ps1
  15. Demo Script: VirtualSwitch.ps1
  16. Demo Script: GuestDisk.ps1
  17. Demo Script: Waste.ps1
  18. Demo Script: CustomAttributes.ps1
  19. Demo Script: RolesPermissions.ps1
  20. Demo Script: StatsIntro.ps1
  21. Demo Script: TopVMHost.ps1
  22. Demo Script: EventReports.ps1
  23. Demo Script: VMLastPoweron.ps1
  24. Demo Script: ReadableCode.ps1
  25. Demo Script: MaxSpeed.ps1
  26. Demo Script: ObjectExtensions.ps1
  27. Demo Script: GetViewGetMember.ps1
  28. No script for this demo.
  29. Demo Script: GuestManagement.ps1
  30. Demo Script: ChangeSwap.ps1
  31. Demo Script: iSCSI.ps1
  32. Demo Script: RDM.ps1
  33. Demo Script: UnsharedVMs.ps1
  34. Demo Script: RDM.ps1
  35. Demo Script: QueueDepth.ps1
  36. Demo Script: AdvancedSwitch.ps1
  37. Demo Script: ESXAdvancedConfig.ps1
  38. Demo Script: Licensing.ps1
  39. Demo Script: FindBottlenecks.ps1
  40. Demo Script: ArchiveLogfiles.ps1
  41. Demo Script: Alarms.ps1
  42. Demo Script: RegisterVMs.ps1
  43. Demo Script: RDMReport.ps1
  44. Demo Script: ESXDNS.ps1