Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Learning PowerCLI for VMware VSphere

You're reading from   Learning PowerCLI for VMware VSphere Automate your Vmware vSphere environment by learning how to install and use PowerCLI. This book takes a practical tutorial approach that will have you automating your daily routine tasks in no time.

Arrow left icon
Product type Paperback
Published in Feb 2014
Publisher
ISBN-13 9781782170167
Length 374 pages
Edition Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Robert van den Nieuwendijk Robert van den Nieuwendijk
Author Profile Icon Robert van den Nieuwendijk
Robert van den Nieuwendijk
Arrow right icon
View More author details
Toc

Table of Contents (17) Chapters Close

Learning PowerCLI
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
1. Introduction to PowerCLI 2. Learning Basic PowerCLI Concepts FREE CHAPTER 3. Working with Objects in PowerShell 4. Managing vSphere Hosts with PowerCLI 5. Managing Virtual Machines with PowerCLI 6. Managing Virtual Networks with PowerCLI 7. Managing Storage with PowerCLI 8. Managing High Availability and Clustering with PowerCLI 9. Managing vCenter with PowerCLI 10. Reporting with PowerCLI Index

Retrieving a list of all of your hosts


Similar to the Get-VM cmdlet, which retrieves your virtual machines, is the Get-VMHost cmdlet, which displays your hosts. The Get-VMHost cmdlet has the following syntax:

Get-VMHost [[-Name] <String[]>] [-NoRecursion] [-Datastore <StorageResource[]>] [-State <VMHostState[]>] [-Location <VIContainer[]>] [-Tag <Tag[]>] [-Server <VIServer[]>] [<CommonParameters>]
Get-VMHost [[-Name] <String[]>] [-DistributedSwitch <DistributedSwitch[]>] [-Tag <Tag[]>] [-Server <VIServer[]>] [<CommonParameters>]
Get-VMHost [[-Name] <String[]>] [-NoRecursion] [-VM <VirtualMachine[]>] [-ResourcePool <ResourcePool[]>] [-Datastore <StorageResource[]>] [-Location <VIContainer[]>] [-Tag <Tag[]>] [-Server <VIServer[]>] [<CommonParameters>]
Get-VMHost -Id <String[]> [-Server <VIServer[]>] [<CommonParameters>]

You see that there are four different parameter sets. They are named: Default, DistributedSwitch, SecondaryParameterSet, and ById. Don't mix parameters from different sets or you will get an error as follows:

PowerCLI C:\> Get-VMHost -Id HostSystem-host-22 -Name 192.168.0.133
Get-VMHost : Parameter set cannot be resolved using the specifiednamed parameters.
At line:1 char:1
+ Get-VMHost -Id HostSystem-host-22 -Name 192.168.0.133
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Get-VMHost], ParameterBindingException
    + FullyQualifiedErrorId :AmbiguousParameterSet,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVMHost

To get a list of all of your hosts, type the following command:

PowerCLI C:\> Get-VMHost

By default, only the Name, ConnectionState, PowerState, NumCPU, CpuUsageMhz, CpuTotalMhz, MemoryUsageGB, MemoryTotalGB, and Version properties are shown. To get a list of all of the properties, type the following command:

PowerCLI C:\> Get-VMHost | Format-List –Property *

State                 : Connected
ConnectionState       : Connected
PowerState            : PoweredOn
VMSwapfileDatastoreId :
VMSwapfilePolicy      : Inherit
ParentId              : ClusterComputeResource-domain-c7
IsStandalone          : False
Manufacturer          : VMware, Inc.
Model                 : VMware Virtual Platform
NumCpu                : 2
CpuTotalMhz           : 4588
CpuUsageMhz           : 54
LicenseKey            : 00000-00000-00000-00000-00000
MemoryTotalMB         : 2047.48828125
MemoryTotalGB         : 1.999500274658203125
MemoryUsageMB         : 965
MemoryUsageGB         : 0.9423828125
ProcessorType         : Intel(R) Core(TM) i5-2415M CPU @ 2.30GHz
HyperthreadingActive  : False
TimeZone              : UTC
Version               : 5.5.0
Build                 : 1331820
Parent                : Cluster01
VMSwapfileDatastore   :
StorageInfo           : HostStorageSystem-storageSystem-22
NetworkInfo           : localhost:sitecomwl306
DiagnosticPartition   : mpx.vmhba1:C0:T0:L0
FirewallDefaultPolicy : VMHostFirewallDefaultPolicy:HostSystem-host-22
ApiVersion            : 5.5
Name                  : 192.168.0.133
CustomFields          : {[AutoDeploy.MachineIdentity, ]}
ExtensionData         : VMware.Vim.HostSystem
Id                    : HostSystem-host-22
Uid                   : /[email protected]:443/VMHost=HostSystem-host-22/
Client                : VMware.VimAutomation.ViCore.Impl.V1.VimClient
DatastoreIdList       : {Datastore-datastore-23}

You can use the Get-VMHost parameters or the Where-Object cmdlet to filter the hosts you want to display, as we did with the Get-VM cmdlet.

Displaying the output in a grid view

Instead of displaying the output of your PowerCLI commands in the PowerCLI console, you can also display the output in a grid view. A grid view is a pop up that looks like a spreadsheet with rows and columns. To display the output of the Get-VMHost cmdlet in a grid view, type the following command:

PowerCLI C:\> Get-VMHost | Out-GridView

The preceding command opens the window of the following screenshot:

You can create filters to display only certain rows, and you can sort columns by clicking on the column header. You can also reorder columns by dragging and dropping them. In the next screenshot, we created a filter to show only the hosts with a CpuUsageMhz value greater than or equal to 70. We also changed the order of the ConnectionState and PowerState columns.

Isn't that cool?

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image