getting started with vmware powercli

36

Click here to load reader

Upload: svea

Post on 26-Feb-2016

113 views

Category:

Documents


10 download

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 Presentation

TRANSCRIPT

Page 1: Getting Started with VMware  PowerCLI

Getting Started with VMware PowerCLI

Jake Robinson, Systems EngineerBluelock

1

Page 2: Getting Started with VMware  PowerCLI

Welcome

2

• Intro• Microsoft Powershell• Break!• VMware PowerCLI• vCloud Powershell• Extra Question/Lab Time

Page 3: Getting Started with VMware  PowerCLI

What is Powershell?

Automation Engine

Scripting Language

Object, not text processing

.NET libraries

Extensible framework

Integrated help system

ISE

3

Page 4: Getting Started with VMware  PowerCLI

The Powershell cmdlet

• Native, compiled command• Always follow verb-noun format

• Get-Beer• Snap-ins• Aliases

4

Page 5: Getting Started with VMware  PowerCLI

Getting Help

• Get-Help • Get-Command• http://bit.ly/15jUeM

5

Page 6: Getting Started with VMware  PowerCLI

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

Page 7: Getting Started with VMware  PowerCLI

Variables

• They store stuff. (objects)• They start with a $.• $jake = “nerd”

7

Page 8: Getting Started with VMware  PowerCLI

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

Page 9: Getting Started with VMware  PowerCLI

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

Page 10: Getting Started with VMware  PowerCLI

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

Page 11: Getting Started with VMware  PowerCLI

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

Page 12: Getting Started with VMware  PowerCLI

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

Page 13: Getting Started with VMware  PowerCLI

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

Page 14: Getting Started with VMware  PowerCLI

Functions

• Reusable code!• Save functions in a .ps1 file• Import functions by “dot-sourcing”

• . C:\scripts\myFunctions.ps1

14

dot space

Page 15: Getting Started with VMware  PowerCLI

Function Example

15

Page 16: Getting Started with VMware  PowerCLI

Powershell ISE

• “Integrated Scripting Environment”• Ooh, colors…• Panes

• Script pane• Command pane• Output pane

16

Page 17: Getting Started with VMware  PowerCLI

Powershell ISE

17

Script Pane

Output Pane

Command Pane

Page 18: Getting Started with VMware  PowerCLI

BREAK TIME!Get-Beer | where {$_.temperature –eq COLD}

18

Page 19: Getting Started with VMware  PowerCLI

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

Page 20: Getting Started with VMware  PowerCLI

VMware PowerCLI

20

Page 21: Getting Started with VMware  PowerCLI

What is PowerCLI?

Powershell Snapin

Over 250 Cmdlets!

Strong Community

Service Console Alternative

21

Page 22: Getting Started with VMware  PowerCLI

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

Page 23: Getting Started with VMware  PowerCLI

Add snapin and connect

• Add-PSSnapin vmware.vimautomation.core• Demo…• Let’s look at their Cmdlets…

• Get-Command –PSSnapin vmware*• Connect-VIServer

• Demo…

23

Page 24: Getting Started with VMware  PowerCLI

Getting information

• Get-Datacenter• Get-Cluster• Get-Datastore• Get-VirtualSwitch• Get-ResourcePool• Get-VM• Get-Harddisk

24

Page 25: Getting Started with VMware  PowerCLI

Getting more detail

• Format-List *• Get-View

• (Advanced)• Returns the ENTIRE .NET object• Including methods and properties!

25

Page 26: Getting Started with VMware  PowerCLI

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

Page 27: Getting Started with VMware  PowerCLI

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

Page 28: Getting Started with VMware  PowerCLI

Cool personal use cases

• The case of the Hex WWNs• The case of the Broken Path• The case of the Over-Powered Hosts

28

Page 29: Getting Started with VMware  PowerCLI

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

Page 30: Getting Started with VMware  PowerCLI

VMware Onyx

30

Page 31: Getting Started with VMware  PowerCLI

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!

Page 32: Getting Started with VMware  PowerCLI

vCloud Powershell

32

Page 33: Getting Started with VMware  PowerCLI

Why the Cloud?

33

Act Quickly

Unknowns

Change yourMind

Page 34: Getting Started with VMware  PowerCLI

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

Page 35: Getting Started with VMware  PowerCLI

vCloud Powershell

• Demo!• Get-vCloudVM• PowerOff-vCloudVM• PowerOn-vCloudVM• Get-vCloudConsole

35

Page 36: Getting Started with VMware  PowerCLI

Set-TheEnd

Twitter: @jakerobinsonWeb: bluelock.com

36