500 likes | 894 Views
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
E N D
Getting Started with VMware PowerCLI Jake Robinson, Systems Engineer Bluelock
Welcome • Intro • Microsoft Powershell • Break! • VMware PowerCLI • vCloudPowershell • Extra Question/Lab Time
The Powershell cmdlet • Native, compiled command • Always follow verb-noun format • Get-Beer • Snap-ins • Aliases
Getting Help • Get-Help • Get-Command • http://bit.ly/15jUeM
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.
Variables • They store stuff. (objects) • They start with a $. • $jake = “nerd”
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
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
Foreach-Object • Foreach-Object • Do something to each object in our pipeline • Get-Process | Foreach-Object {Write-host “Jake” $_.name} Process Write-Host “Jake” $_.name Process Write-Host “Jake” $_.name Process Write-Host “Jake” $_.name Process Write-Host “Jake” $_.name Get-Process ForEach-Object
Functions • Reusable code! • Save functions in a .ps1 file • Import functions by “dot-sourcing” • . C:\scripts\myFunctions.ps1 space dot
Powershell ISE • “Integrated Scripting Environment” • Ooh, colors… • Panes • Script pane • Command pane • Output pane
Powershell ISE Script Pane Output Pane Command Pane
BREAK TIME! Get-Beer | where {$_.temperature –eq COLD}
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/
Adding the Snapinvs Running PowerCLI • The PowerCLI icon generates aliases • (egGet-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
Add snapin and connect • Add-PSSnapinvmware.vimautomation.core • Demo… • Let’s look at their Cmdlets… • Get-Command –PSSnapinvmware* • Connect-VIServer • Demo…
Getting information • Get-Datacenter • Get-Cluster • Get-Datastore • Get-VirtualSwitch • Get-ResourcePool • Get-VM • Get-Harddisk
Getting more detail • Format-List * • Get-View • (Advanced) • Returns the ENTIRE .NET object • Including methods and properties!
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!
Making Changes • Start/Stop/Reset VMs (hard) • Shutdown/Restart VMGuest (Soft) • VM settings • The –WhatIf switch • Create VMs • The –RunAsync switch • Delete VMs • -DeletePermanently
Cool personal use cases • The case of the Hex WWNs • The case of the Broken Path • The case of the Over-Powered Hosts
Your turn… • 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
Onyx • It’s a vCenter Proxy • Captures traffic, turns it into PowerShell Code • http://labs.vmware.com/flings/onyx • Demo… Code! vSphere Client Onyx vCenter
Why the Cloud? Act Quickly Unknowns Change your Mind
vCloudPowershell • 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
vCloudPowershell • Demo! • Get-vCloudVM • PowerOff-vCloudVM • PowerOn-vCloudVM • Get-vCloudConsole
Set-TheEnd Twitter: @jakerobinson Web: bluelock.com