Managing VMware With PowerShell

30
Managing VMware Infrastructure with VI Toolkit (for Windows) Carter Shanklin VMware Infrastructure Product Manager VMware

description

Slide deck from a webinar I gave on managing VMware Virtual Infrastructure using PowerShell.

Transcript of Managing VMware With PowerShell

Page 1: Managing VMware With PowerShell

Managing VMware Infrastructurewith VI Toolkit (for Windows)

Carter ShanklinVMware Infrastructure Product Manager

VMware

Page 2: Managing VMware With PowerShell

22

Overview

What is the VI Toolkit (for Windows)

The top 3 ways your life gets easier with the toolkit

Interactive demos

Resources to help you use the toolkit

How to get the toolkit

Page 3: Managing VMware With PowerShell

33

What is the VI Toolkit (for Windows)?

The VI Toolkit is a platform for the automation of administrative tasks.

Remotely manage and automate VI.

The VI Toolkit is easy to use.

The commands are designed from the ground for ease of use.

You don’t have to be a developer.

Many useful tasks can be accomplished with only a couple of commands.

Based on PowerShell.

If you are a Windows admin, you either know some PowerShell or plan to learn it.

Page 4: Managing VMware With PowerShell

44

What is PowerShell?

PowerShell is Microsoft’s foundation for automation.

Starting in 2008, all Microsoft enterprise software must enable automation through PowerShell.

Other vendors are adopting the same approach.

PowerShell lets you manage different applications in a consistent way.

Page 5: Managing VMware With PowerShell

55

Top 3 Ways Your Life is Easier with the Toolkit

Save time by automating repetitive tasks. 100 is just as easy as 1.

Automate time consuming tasks for greater productivity. Let your scripts do the waiting.

Turn questions into answers with our large and growing set of online resources.

Page 6: Managing VMware With PowerShell

66

Disconnect CD-ROM and floppy drives to enable VMotion.

PowerShell:

2 Commands

Full Automation

Manually:

1 Minute / VM

BORING!

Automate Repetitive Tasks

Page 7: Managing VMware With PowerShell

77

Automate Lengthy Tasks For Greater Productivity

VM Migration

Manually:

10 Minutes per VM

PowerShell:

1 Command

Full Automation

Page 8: Managing VMware With PowerShell

88

You’ve Got Questions, We’ve Got Answers

With the help of our forums, our users have:

Deployed more than 200 VMs from a template.

Configured VMware tools to automatically upgrade on all VMs.

Load balance from their ESX systems to their storage arrays.

Changed the video memory on 2,000 virtual desktops.

Created custom reports.

And much more!

Page 9: Managing VMware With PowerShell

99

A Tour Of Windows PowerShell

PowerShell comes with over 100 commands called cmdlets, and extensive documentation.

PowerShell has syntax conventions.

Verb-Noun.

Fosters a common look and feel across applications.

PowerShell supports discoverability.

The Get-Member cmdlets lets you see what is possible with objects.

PowerShell also provides access to all of .NET, COM and WMI.

Page 10: Managing VMware With PowerShell

1010

A Tour of The VI Toolkit (for Windows)

get-vicommand – shows all 125 commands.

VM Lifecycle:

New-VM, Start-VM, Set-VM

Snapshots:

Get-Snapshot, New-Snapshot, Set-VM

Templates and Customization Specs:

New-Template, New-OSCustomizationSpec, New-VM

Virtual Switches:

New-VirtualSwitch, New-VirtualPortGroup, Set-VirtualSwitch

Performance Statistics and Monitoring:

Get-Stat

Page 11: Managing VMware With PowerShell

1111

More than Just Virtual Infrastructure

The VI Toolkit (for Windows) provides 125 cmdlets for VI.

VMware Update Manager provides 13 cmdlets to help you automate keeping your VI up-to-date.

Features:

Download updates.

Manipulate baselines.

Remediate.

Even more!

Page 12: Managing VMware With PowerShell

Demos

Page 13: Managing VMware With PowerShell

1313

Demos: Snapshots

Snapshot every powered-on VM:

Get-VM | Where { $_.PowerState –eq “PoweredOn” } |

New-Snapshot –Name “New Snapshot”

Delete all of those snapshots:

Get-VM | Get-Snapshot |

Where { $_.Name –eq “New Snapshot” } |

Remove-Snapshot

Find all snapshots older than 1 month:

Get-VM | Get-Snapshot |

Where { $_.Created –lt (Get-Date).addMonths(-1) }

Page 14: Managing VMware With PowerShell

1414

Demos: Networking

Move every VM on Network “Provisioning” to Network “Production”

Get-VM | Get-NetworkAdapter |

Where { $_.NetworkName –eq “Provisioning” } |

Set-NetworkAdapter –NetworkName “Production”

Create a virtual switch on interface vmnic1

Get-VMHost | New-VirtualSwitch –name “Second Switch” `

-nic vmnic1

Configure a new VMKernel on these new switches for management and VMotion.

Get-VMHost | New-VMHostNetworkAdapter `

-virtualswitch (get-virtualswitch -name “Second Switch”) `

-vmotionenabled:$true -portgroup blah2 -ip 10.24.0.1 `

–subnetmask 255.0.0.0

Page 15: Managing VMware With PowerShell

1515

Demos: Configuration Management

Ensure all your VMs have at least 1GB of RAM:

Get-VM | Where { $_.MemoryMB –lt 1024 } |

Set-VM –MemoryMB 1024

Update VMware Tools in every VM in the “Americas 1” datacenter:

Get-Datacenter “Americas 1” | Get-VM | Update-Tools

Page 16: Managing VMware With PowerShell

1616

Demos: Storage

Rescan every HBA on all hosts:

Get-VMHost | Get-VMHostStorage -RescanAllHba

Create new datastores:

NFS: Get-VMHost |

New-Datastore –Nfs –NfsHost myserver –name “New Datastore”

FC / iSCSI:

Note: In the 1.0 toolkit you’ll need to retreive SCSI Luns using the Host’s StorageSystem.

Get-VMHost |

New-Datastore -Vmfs -Path $lunpath.LunPath `

–Name “New Datastore”

Page 17: Managing VMware With PowerShell

1717

Demos: Reporting

Determine statistics about VM disk usage:

( get-vm | foreach { ($_ | get-harddisk | measure-object -property CapacityKB -sum).Sum } ) | measure-object -average -sum -maximum –minimum

Sort hosts by number of VMs hosted:

get-vm | select name, @{ Name="Host"; Expression={$_.host.name} } | group Host | select name, count | sort count

Sort hosts by CPU utilized in the past 45 minutes:

get-vmhost | select Name, @{Name="Average CPU Usage (%)"; Expression={ ($_ | get-stat | where { $_.MetricId -eq "cpu.usage.average" } | measure-object -property Value -average | select average).average } } | sort

Page 18: Managing VMware With PowerShell

1818

A Tour of Available Resources

Many resources are available to support automation and give you ideas about what can be done.

The PowerShell forum.

The FAQ.

The PowerShell blog.

Page 19: Managing VMware With PowerShell

1919

The PowerShell Forum

http://communities.vmware.com/community/developer/windows_toolkit

People in the forum have found support for things like:

Clone templates.

Mask CPU features to enable VMotion.

Make firewall configuration changes.

Configure HA and DRS.

Much, much more.

Page 20: Managing VMware With PowerShell

2020

From the Forum

Changing the boot order of VMs.

Sometimes the BIOS boot order of a VM needs to be changed.

The solution (from LucD in the PowerShell Forum):

$spec = New-Object VMware.Vim.VirtualMachineConfigSpec$spec.extraConfig += New-Object VMware.Vim.OptionValue$spec.extraConfig[0].key = "bios.bootDeviceClasses"$spec.extraConfig[0].value = "allow:cd,hd"get-vm | % { (get-view $_.ID).ReconfigVM_Task($spec) }

Page 21: Managing VMware With PowerShell

2121

The PowerShell FAQ

http://communities.vmware.com/docs/DOC-4210.

Contains 25 frequently asked questions about using PowerShell to manage VI.

Examples:

Creating VMs on particular datastores.

Setting resource levels on all VMs.

Snapshotting multiple VMs.

Page 22: Managing VMware With PowerShell

2222

From the FAQ

Setting resource levels on VMs.

VC upgrades may reset custom resource levels.

The solution:

Get-VM | % { $view = Get-View $_.ID $spec = new-object VMware.Vim.VirtualMachineConfigSpec $spec.CPUAllocation = New-Object VMware.Vim.ResourceAllocationInfo $spec.CpuAllocation.Shares = New-Object VMware.Vim.SharesInfo $spec.CpuAllocation.Shares.Level = "normal" $spec.CpuAllocation.Limit = -1 $view.ReconfigVM_Task($spec) }

Page 23: Managing VMware With PowerShell

2323

The PowerShell Blog

http://blogs.vmware.com/vipowershell/

Contains periodic ideas and resources for making VI management easier and more effective.

Jonathan Walz and Hal Rottenberg have an excellent podcast that is devoted to Windows PowerShell, if you haven’t listened you should definitely give it a try.

Page 24: Managing VMware With PowerShell

2424

From the Blog

Configuring storage paths.

Configuring storage paths is an important step for performance optimization.

Configuring this manually is usually not practical.

The blog gives examples of how to do it.

Example: Enabling round-robin multipathing on all hosts.

Page 25: Managing VMware With PowerShell

2525

That’s Not All!

PowerShell has an extensive set of 3rd party tools to help you do your own integrations.

Tool Name Features Offered

PowerGUI Graphical PowerShell frontend

PowerGadgets Visual dashboards and reports

NetCmdlets Provides network access (e.g. ssh)

Quest AD Cmdlets Manage Microsoft Active Directory

SpecOps Software Execute PowerShell using group policy

Page 26: Managing VMware With PowerShell

2626

3rd Party Tools: PowerGUI

PowerGUI is a graphical interface to PowerShell.

Easy administration using the MMC-like PowerGUI Admin Editor.

Easy script editing with the PowerGUI Script Editor.

Automatically generate PowerShell code with the PowerGUI Admin Editor.

Page 27: Managing VMware With PowerShell

2727

3rd Party Tools: PowerGadgets

Monitoring with Custom Dashboards

Page 28: Managing VMware With PowerShell

2828

Are You a PowerShell Scripting Guru?

• Enter PowerShell Scripting Contest• Win great prizes, show off your scripting skills• First Prize: Free Trip to VMworld – Las Vegas or $5,000 • Second Prize: Mac Air w/ Fusion or $2500• Third Prize: Xbox Elite or $500 Cash• Contest Ends August 30th, 2008• Winner Announced September 7, 2008• For more information: http://vmware.com/go/powershellcontest

Page 29: Managing VMware With PowerShell

Questions?

Please use the Q&A panelof your WebEx console

For more Webcast information, please visitwww.vmware.com/go/webcasts

This Webcast has been recorded, and the slideswill be ready for download within 48 hours.

Once the presentation is available, an e-mail will be sent to youwith directions on how to access the recorded version.