Introduction To Managing VMware With PowerShell
-
Upload
hal-rottenberg -
Category
Technology
-
view
7.454 -
download
0
description
Transcript of Introduction To Managing VMware With PowerShell
Hal Rottenberg [email protected]
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)
IntroductionFeature overviewDemo 1: new providersNew CmdletsDemo 2: “wiki deploy”Demo 3: Creating a VMDemo 4: Access VI SDK
Programming API Web service (WSDL) Samples included for Java, C, C# Low level
Scripting API Perl and COM interfaces available Wrapper for web services
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
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
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
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}
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}
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!
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
New-Datacenter New-Cluster Add-VMHost New-VM
Create folders “wiki-style”
Cmdlets used: New-VM
Remove-SnapshotMove-VMSet-NetworkAdapterRestart-VMGuest
Cmdlets used: New-Snapshot
get-vm MYSERVER | move-vm -dest (get-vmhost ESX2)
get-cluster TEST | get-vm | move-vm –dest (get-cluster PRODUCTION)
Get-VIEventGet-TaskGet-LogGet-Stat
Cmdlets used: Get-VIEvent
When the simplified interface doesn’t cut it…you can always work with the SDK
Cmdlets used Get-View
ISCSI Configuration
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