Introduction To Managing VMware With PowerShell

25
Hal Rottenberg [email protected]

description

Introduction to the VI Toolkit which is available at http://vmware.com/go/powershell. Companion to my book which is at http://sapienpress.com/vmware.asp

Transcript of Introduction To Managing VMware With PowerShell

Page 1: Introduction To Managing VMware With PowerShell

Hal Rottenberg [email protected]

Page 2: Introduction To Managing VMware With PowerShell

Hal Rottenberg [email protected] Over 12 years in the IT industry; everything

from helpdesk, to sysadmin, to technical consultant

Author, Managing VMware Infrastructure with PowerShell: TFM from Sapien Press (due out “as soon as he can possibly get it done”)

Community Director, PowerShellCommunity.org

Co-Host, PowerScripting Podcast (powerscripting.net)

Blog Author, TechProsaic (halr9000.com)

Page 3: Introduction To Managing VMware With PowerShell

IntroductionFeature overviewDemo 1: new providersNew CmdletsDemo 2: “wiki deploy”Demo 3: Creating a VMDemo 4: Access VI SDK

Page 4: Introduction To Managing VMware With PowerShell

Programming API Web service (WSDL) Samples included for Java, C, C# Low level

Scripting API Perl and COM interfaces available Wrapper for web services

Page 5: Introduction To Managing VMware With PowerShell

You still must learn the VI SDK

Higher level than SDK, but not by much

Perl interface not familiar to Windows admins

COM interface was not very popular, hard to find examples

Page 6: Introduction To Managing VMware With PowerShell

PowerShell snap-in Client-side “automation objects”

correspond to server-side “managed objects” and “managed entities”

Not just a web service wrapper Favors action-oriented cmdlets over

object methods Goal: 80% of tasks will not require SDK Ability to access the SDK for more

complex tasks

Page 7: Introduction To Managing VMware With PowerShell

Fully supported: Virtual Center 2.x ESX Server 3.x (including 3i)

Unofficially supported: VMware Server 2.0 beta

Works with PowerShell v1 or v2 CTP

Page 8: Introduction To Managing VMware With PowerShell

Includes over 120 cmdletsCount Name Group----- ---- ----- 1 Add {Add-VMHost} 1 Connect {Connect-VIServer} 1 Disconnect {Disconnect-VIServer} 1 Dismount {Dismount-Tools} 37 Get {Get-CDDrive, Get-Cluster, Get-Datacenter,... 1 Mount {Mount-Tools} 7 Move {Move-Cluster, Move-Datacenter, Move-Folde... 19 New {New-CDDrive, New-Cluster, New-CustomField... 20 Remove {Remove-CDDrive, Remove-Cluster, Remove-Cu... 2 Restart {Restart-VMGuest, Restart-VMHostService} 27 Set {Set-CDDrive, Set-Cluster, Set-CustomField... 1 Shutdown {Shutdown-VMGuest} 2 Start {Start-VM, Start-VMHostService} 3 Stop {Stop-Task, Stop-VM, Stop-VMHostService} 2 Suspend {Suspend-VM, Suspend-VMGuest} 1 Test {Test-VMHostSNMP} 1 Update {Update-Tools} 1 Wait {Wait-Task}

Count Name Group----- ---- ----- 1 Add {Add-VMHost} 1 Connect {Connect-VIServer} 1 Disconnect {Disconnect-VIServer} 1 Dismount {Dismount-Tools} 37 Get {Get-CDDrive, Get-Cluster, Get-Datacenter,... 1 Mount {Mount-Tools} 7 Move {Move-Cluster, Move-Datacenter, Move-Folde... 19 New {New-CDDrive, New-Cluster, New-CustomField... 20 Remove {Remove-CDDrive, Remove-Cluster, Remove-Cu... 2 Restart {Restart-VMGuest, Restart-VMHostService} 27 Set {Set-CDDrive, Set-Cluster, Set-CustomField... 1 Shutdown {Shutdown-VMGuest} 2 Start {Start-VM, Start-VMHostService} 3 Stop {Stop-Task, Stop-VM, Stop-VMHostService} 2 Suspend {Suspend-VM, Suspend-VMGuest} 1 Test {Test-VMHostSNMP} 1 Update {Update-Tools} 1 Wait {Wait-Task}

Page 9: Introduction To Managing VMware With PowerShell

Also includes two PSProviders Remote filesystem (datastore) access via

VimDatastore provider Hierarchical management of Folders,

Datacenters, VMHosts, VMs using VimInventory provider

Name Capabilities Drives---- ------------ ------VimDatastore Filter, ShouldProcess {DS}VimInventory Filter {VI}

Name Capabilities Drives---- ------------ ------VimDatastore Filter, ShouldProcess {DS}VimInventory Filter {VI}

Page 10: Introduction To Managing VMware With PowerShell

VimInventoryVimDatastore

New-PSDrive -Name VI -PSProvider VimInventory ` -Root '/' -location (Get-Folder -NoRecursion)New-PSDrive -Name DS -PSProvider VimDatastore ` -Root '/' -location (Get-Datastore $DatastoreName)

New-PSDrive -Name VI -PSProvider VimInventory ` -Root '/' -location (Get-Folder -NoRecursion)New-PSDrive -Name DS -PSProvider VimDatastore ` -Root '/' -location (Get-Datastore $DatastoreName)

EXPERIMENTAL!

Page 11: Introduction To Managing VMware With PowerShell
Page 12: Introduction To Managing VMware With PowerShell

PS > Get-VM

Name PowerState Num CPUs Memory (MB)---- ---------- -------- -----------SDK-RHAS4U4 PoweredOff 1 512SDK-W2003ENT PoweredOff 1 256fudgeapp01 PoweredOff 1 256fudgedb01 PoweredOff 1 512vcenter.halr9000.com PoweredOn 2 1500fudgedb02 PoweredOff 1 1024SDK-XPSP2 PoweredOff 1 256

PS > Get-VM

Name PowerState Num CPUs Memory (MB)---- ---------- -------- -----------SDK-RHAS4U4 PoweredOff 1 512SDK-W2003ENT PoweredOff 1 256fudgeapp01 PoweredOff 1 256fudgedb01 PoweredOff 1 512vcenter.halr9000.com PoweredOn 2 1500fudgedb02 PoweredOff 1 1024SDK-XPSP2 PoweredOff 1 256

PS > Get-VMHost

Name State Id---- ----- --192.168.0.51 Connected HostSys...192.168.0.55 Connected HostSys...

PS > Get-VMHost

Name State Id---- ----- --192.168.0.51 Connected HostSys...192.168.0.55 Connected HostSys...

PS > Get-VM vcenter.halr9000.com | Get-CDDrive

ISOPath :HostDevice :RemoteDevice :ConnectionState : VMware.VimAutomation.Client20.ConnectInfoImplID : VirtualMachine-vm-158/3000Name : CD/DVD Drive 1

PS > Get-VM vcenter.halr9000.com | Get-CDDrive

ISOPath :HostDevice :RemoteDevice :ConnectionState : VMware.VimAutomation.Client20.ConnectInfoImplID : VirtualMachine-vm-158/3000Name : CD/DVD Drive 1

PS > Get-Cluster "test cluster" | fl

HAEnabled : FalseHAAdmissionControlEnabled : FalseHAFailoverLevel : 1DRSEnabled : FalseDRSMode : FullyAutomatedCustomFields : {}ID : ClusterComputeResource-domain-c449Name : Test Cluster

PS > Get-Cluster "test cluster" | fl

HAEnabled : FalseHAAdmissionControlEnabled : FalseHAFailoverLevel : 1DRSEnabled : FalseDRSMode : FullyAutomatedCustomFields : {}ID : ClusterComputeResource-domain-c449Name : Test Cluster

Get-VM Get-VMHost Get-CDDrive Get-Cluster

Page 13: Introduction To Managing VMware With PowerShell

New-Datacenter New-Cluster Add-VMHost New-VM

Page 14: Introduction To Managing VMware With PowerShell

Create folders “wiki-style”

Page 15: Introduction To Managing VMware With PowerShell

Cmdlets used: New-VM

Page 16: Introduction To Managing VMware With PowerShell

Remove-SnapshotMove-VMSet-NetworkAdapterRestart-VMGuest

Page 17: Introduction To Managing VMware With PowerShell

Cmdlets used: New-Snapshot

Page 18: Introduction To Managing VMware With PowerShell

get-vm MYSERVER | move-vm -dest (get-vmhost ESX2)

get-cluster TEST | get-vm | move-vm –dest (get-cluster PRODUCTION)

Page 19: Introduction To Managing VMware With PowerShell
Page 20: Introduction To Managing VMware With PowerShell

Get-VIEventGet-TaskGet-LogGet-Stat

Page 21: Introduction To Managing VMware With PowerShell

Cmdlets used: Get-VIEvent

Page 22: Introduction To Managing VMware With PowerShell

When the simplified interface doesn’t cut it…you can always work with the SDK

Cmdlets used Get-View

ISCSI Configuration

Page 23: Introduction To Managing VMware With PowerShell
Page 24: Introduction To Managing VMware With PowerShell

VI Toolkit: http://vmware.com/go/powershell VI Toolkit blog:

http://blogs.vmware.com/vipowershell/ VI Toolkit Community:

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

PowerShellCommunity.org: http://powershellcommunity.org

PowerScripting Podcast: http://powerscripting.net

Managing VI with PowerShell: TFM: http://sapienpress.com/vmware.asp

Hal’s Blog: http://halr9000.com

Page 25: Introduction To Managing VMware With PowerShell