Glimpse of power of VMware VSphere Power CLI

In this article I am going to show the basic usage of VSphere PowerCLI commands. I found them very useful. Once again it convince me to use CLI instead of GUI. I know its  easy to do operations from GUI in case of VMware but if we want to collect information for whole environment I guess these commands very useful.

  • How to Connect to VCenter server ? We can also connect to ESXi

PS C:\> Connect-VIServer 192.168.111.127 -user root -password root123

Name Port User
—- —- —-
192.168.111.127 443 root

  • How to get the version of Power CLI which  we are using ?

PS C:\> Get-PowerCLIVersion

PowerCLI Version
—————-
VMware vSphere PowerCLI 5.5 Release 1 build 1295336
—————
Snapin Versions
—————
VMWare AutoDeploy PowerCLI Component 5.5 build 1262826
VMWare ImageBuilder PowerCLI Component 5.5 build 1262826
VMware License PowerCLI Component 5.5 build 1265954
VMware VDS PowerCLI Component 5.5 build 1295334
VMware vSphere PowerCLI Component 5.5 build 1295334

  • How to get the processes running ? Output truncated.

PS C:\> Get-Process

Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName
——- —— —– —– —– —— — ———–
83 8 1328 3952 42 1420 armsvc
83 8 1476 4504 32 1540 ChargeService
51 6 2468 6484 60 1.54 5072 conhost
510 12 2544 4648 48 540 csrss
516 22 3864 35100 194 648 csrss
134 13 29128 27964 135 36.68 1708 dwm
858 52 38984 66864 351 15.49 1736 explorer
99 7 2476 6032 48 1504 HeciServer
88 8 3980 8004 69 0.02 2332 hkcmd
0 0 0 24 0 0 Idle

  • How to get the services running ?

PS C:\> Get-Service

Status Name DisplayName
—— —- ———–
Running AdobeARMservice Adobe Acrobat Update Service
Stopped AeLookupSvc Application Experience
Stopped ALG Application Layer Gateway Service
Stopped AppIDSvc Application Identity
Running Appinfo Application Information
Stopped AppMgmt Application Management
Stopped aspnet_state ASP.NET State Service
Running AudioEndpointBu… Windows Audio Endpoint Builder
Running AudioSrv Windows Audio
Stopped AxInstSV ActiveX Installer (AxInstSV)
Stopped BDESVC BitLocker Drive Encryption Service
Running BFE Base Filtering Engine

  • How to get the ESXi hosts present in Vcenter server?

PS C:\> Get-VMHost

Name ConnectionState PowerState NumCpu CpuUsageMhz CpuTotalMhz MemoryUsageGB MemoryTotalGB Version
—- ————— ———- —— ———– ———– ————- ————- ——-
192.168.111.132 Connected PoweredOn 2 168 6800 1.144 4.000 5.5.0
192.168.111.130 Connected PoweredOn 2 339 6800 1.150 4.000 5.5.0

  • How to get the Guests present in VCenter ?

PS C:\> Get-VM

Name PowerState Num CPUs MemoryGB
—- ———- ——– ——–
VMware vCenter-1 PoweredOff 2 1.000
Vcenter1-app PoweredOff 2 1.000
Red-Linux1 PoweredOn 2 1.000

  • How to get the name of Datacenter ?

PS C:\> Get-Datacenter

Name
—-
DC1

  • How to get information related to Datastore ?

PS C:\> Get-Datastore

Name FreeSpaceGB CapacityGB
—- ———– ———-
esx2:local-1 38.674 39.750
esx1:local-1 15.781 39.750
ISCSIDatastore1 18.851 19.750

  • How to get information related to ISCSI target ?

PS C:\> Get-IScsiHbaTarget

Address Port Type
——- —- —-
192.16.112.9 3260 Static
192.168.112.9 3260 Static

  • How to get information related to inventory ?

PS C:\> Get-Inventory

Name Type Id
—- —- —
Datacenters Folder Folder-group-d1
DC1 Datacenter Datacenter-d…
network Folder Folder-group…
datastore Folder Folder-group…
vm Folder Folder-group…
host Folder Folder-group…
Red-Linux1 VirtualMachine VirtualMachi…
Vcenter1-app VirtualMachine VirtualMachi…
VMware vCenter-1 VirtualMachine VirtualMachi…
PUNE Folder Folder-group…
Resources ResourcePool ResourcePool…
192.168.111.130 VMHost HostSystem-h…
Resources ResourcePool ResourcePool…
192.168.111.132 VMHost HostSystem-h…

  • How to get information related to Network adapter for particular VM ?

PS C:\> Get-NetworkAdapter Red-Linux1

Name Type NetworkName MacAddress WakeOnLan
Enabled
—- —- ———– ———- ———
Network adapter 1 Vmxnet3 VM Network 00:0c:29:ed:77:0f True

  • How to get various log types present  ?

PS C:\> Get-LogType

Key Summary
— ——-
vpxd:vpxd-6.log vCenter Server log in ‘plain’ format
vpxd:vpxd-alert-6… vCenter Server log in ‘plain’ format
vpxd:vpxd-alert.log vCenter Server log in ‘plain’ format
vpxd:vpxd-profile… vCenter Server log in ‘plain’ format
vpxd:vpxd-profile… vCenter Server log in ‘plain’ format
vpxd:vpxd.log vCenter Server log in ‘plain’ format
vpxd:vpxd_cfg.log vCenter Server log in ‘plain’ format
vpxd-profiler:vpx… vpxd-profiler
vpxd-profiler:vpx… vpxd-profiler

 

I am digging up more on this very soon I will come up with action oriented commands.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s