getting started with vmware powercli
DESCRIPTION
Getting Started with VMware PowerCLI. Jake Robinson, Systems Engineer Bluelock. Welcome. Intro Microsoft Powershell Break! VMware PowerCLI vCloud Powershell Extra Question/Lab Time. What is Powershell ?. The Powershell cmdlet. Native, compiled command - PowerPoint PPT PresentationTRANSCRIPT
Getting Started with VMware PowerCLI
Jake Robinson, Systems EngineerBluelock
1
Welcome
2
• Intro• Microsoft Powershell• Break!• VMware PowerCLI• vCloud Powershell• Extra Question/Lab Time
What is Powershell?
Automation Engine
Scripting Language
Object, not text processing
.NET libraries
Extensible framework
Integrated help system
ISE
3
The Powershell cmdlet
• Native, compiled command• Always follow verb-noun format
• Get-Beer• Snap-ins• Aliases
4
Getting Help
• Get-Help • Get-Command• http://bit.ly/15jUeM
5
Piping and the Pipeline
• The “pipe”• Passes output(object) to another command• Get-Process notepad | Stop-Process• Get-Process | Where-Object {$_.name –eq notepad} |
Stop-Process
• Woah, what the heck is “$_”• Special variable for “This.”• Basically, whatever object is currently in the pipeline.
6
Variables
• They store stuff. (objects)• They start with a $.• $jake = “nerd”
7
Some important Variables
8
Variable Name Description
$_The current pipeline object; used in script blocks, filters, the process clause of functions, where-object, foreach-object and switch
$^ contains the first token of the last line input into the shell$$ contains the last token of last line input into the shell$? Contains the success/fail status of the last statement
$Args Used in creating functions that require parameters$Env:Path Environmental Path to files.
$Error If an error occurred, the object is saved in the $error PowerShell variable$foreach Refers to the enumerator in a foreach loop.$HOME The user's home directory; set to %HOMEDRIVE%\%HOMEPATH%$Input Input piped to a function or code block$Match A hash table consisting of items found by the –match operator.
$MyInvocation Information about the currently script or command-line$Host Information about the currently executing host
$LastExitCode The exit code of the last native application to run$true Boolean TRUE$false Boolean FALSE$null A null object
$OFSOutput Field Separator, used when converting an array to a string.By default, this is set to the space character.
$ShellIDThe identifier for the shell. This value is used by the shell to determine the ExecutionPolicy and what profiles are run at startup.
$StackTrace contains detailed stack trace information about the last error
Arithmetic and Assignment Operators
9
Operator Definition+ Adds two things together. (numbers, strings, etc)- Subtract (also can make a number negative!)* Multiply/ Divide% Divides and returns the remainder
Operator Definition= Assigns a value
+= Increases value by specified amount-= Decreases value by specified amount*= Multiplies value by specified amount/= Divides value by specified amount%= Divides value by specified amount (remainder)++ Increment by 1.-- Decrement by 1
Comparison Operators
10
Operator Definition-lt Less than-le Less than or equal to-gt Greater than-ge Greater than or equal to-eq Equal to-ne Not Equal to
-containsDetermine elements in a group. This always returns Boolean $True or $False.
-notcontainsDetermine excluded elements in a groupThis always returns Boolean $True or $False.
-like Like - uses wildcards for pattern matching-notlike Not Like - uses wildcards for pattern matching
-matchMatch - uses regular expressions for pattern matching
-notmatchNot Match - uses regular expressions for pattern matching
Filtering and Formatting
• Where-Object• Only show me certain objects• Get-Process | Where-Object {$_.WS –gt 10MB}
• Select-Object• Only show me certain properties of an object• Get-Process | select name, id
11
Filtering and Formatting• Format-List
• Vertical view of properties• Not fun to look at when you have more that one object• Great for deep-diving into a single object• Format-List * (displays all properties of an object)
• Format-Table• Horizontal view of properties• Not fun to look at when you have lots of properties• Great for viewing a lot of objects and a few properties
12
Foreach-Object
• Foreach-Object• Do something to each object in our pipeline• Get-Process | Foreach-Object {Write-host “Jake”
$_.name}
13
ProcessProcessProcessProcess
Get-Process ForEach-Object
Write-Host “Jake” $_.nameWrite-Host “Jake” $_.nameWrite-Host “Jake” $_.nameWrite-Host “Jake” $_.name
Functions
• Reusable code!• Save functions in a .ps1 file• Import functions by “dot-sourcing”
• . C:\scripts\myFunctions.ps1
14
dot space
Function Example
15
Powershell ISE
• “Integrated Scripting Environment”• Ooh, colors…• Panes
• Script pane• Command pane• Output pane
16
Powershell ISE
17
Script Pane
Output Pane
Command Pane
BREAK TIME!Get-Beer | where {$_.temperature –eq COLD}
18
Bluelock is Hiring!Want a Challenge? Passionate about virtualization?
• Systems Engineer• Software Engineer• Support Specialist (2nd Shift)• Engagement Manager• Account Executive• Accounting Specialist
For more info:
http://www.bluelock.com/information-center/careers/
19
VMware PowerCLI
20
What is PowerCLI?
Powershell Snapin
Over 250 Cmdlets!
Strong Community
Service Console Alternative
21
Adding the Snapin vs Running PowerCLI
• The PowerCLI icon generates aliases• (eg Get-PowerCLIHelp)• A little slower startup, in my experience
• Adding the snapin to powershell• Easy to add snapin• Don’t rely on aliases• Easier for task scheduling• Add to Powershell profile
22
Add snapin and connect
• Add-PSSnapin vmware.vimautomation.core• Demo…• Let’s look at their Cmdlets…
• Get-Command –PSSnapin vmware*• Connect-VIServer
• Demo…
23
Getting information
• Get-Datacenter• Get-Cluster• Get-Datastore• Get-VirtualSwitch• Get-ResourcePool• Get-VM• Get-Harddisk
24
Getting more detail
• Format-List *• Get-View
• (Advanced)• Returns the ENTIRE .NET object• Including methods and properties!
25
Reporting
• There’s a Cmdlet for that…• ConvertTo-HTML• Export-CSV• Out-File
• vCheck• http://www.virtu-al.net/featured-scripts/vcheck/• LOTS of fun information!
26
Making Changes
• Start/Stop/Reset VMs (hard)• Shutdown/Restart VMGuest (Soft)• VM settings
• The –WhatIf switch• Create VMs
• The –RunAsync switch• Delete VMs
• -DeletePermanently
27
Cool personal use cases
• The case of the Hex WWNs• The case of the Broken Path• The case of the Over-Powered Hosts
28
Your turn…
vCenter Server: Sorry, lab not available.Username: labuserPassword: Ilovepowercli
29
• Connect-VIServer <vCenter Server>• Browse around with some Get Cmdlets• Create a new VM (use your first initial, last name as the VM)• Power it up! Create a snapshot!• Power it down, Delete the VM!• Can you
VMware Onyx
30
Onyx
• It’s a vCenter Proxy• Captures traffic, turns it into PowerShell Code
• http://labs.vmware.com/flings/onyx• Demo…
31
OnyxvSphere Client vCenter
Code!
vCloud Powershell
32
Why the Cloud?
33
Act Quickly
Unknowns
Change yourMind
vCloud Powershell
• The inventory dilemma again!• Can’t get the info from vCenter• All the info was in vCloud Director
• The vCloud API• RESTful• Nothing existed for Powershell
34
vCloud Powershell
• Demo!• Get-vCloudVM• PowerOff-vCloudVM• PowerOn-vCloudVM• Get-vCloudConsole
35
Set-TheEnd
Twitter: @jakerobinsonWeb: bluelock.com
36