Archive

Posts Tagged ‘Powershell’

List ARP table entries of an ESXi

September 13, 2011 2 comments

Like we found before for netstat there is no arp command available from within ESXi Tech Support Mode, so how can you list the ARP table entries if you need to? Or how can you do it remotely either with vCLI or PowerCLI?

In this quick post I’ll show you the different ways to list the ARP table entries of an ESXi server, as always both for ESXi4 and ESXi5.

Tech Support Mode

From ESXi Tech Support Mode we need to relay in esxcli.

ESXi4:

ESXi5:

vCLI

Again we need esxcli in order to get the ARP table.

PowerCLI

In this case we are going to use esxcli but trough the Get-EsxCli cmdlet. First we retrieve the esxcli instance and then we get the ARP table list.

ESXi4:

ESXi5:

Juanma.

How to get ESX(i) network connections using PowerCLI

September 7, 2011 Leave a comment

In a previous post I described how to get the network connections of an ESXi server using esxcli from Tech Support Mode and vSphere CLI. Following I’ll show you how to get the same information from an ESXi 4.1 and 5.0 using PowerCLI.

The key to perform this task s the Get-EsxCli cmdlet. This command was introduced with PowerCLI 4.1.1 and its purpose is to expose the esxcli framework.

The first task to do with Get-EsxCli is to create a wrapper using a variable that will expose the esxcli functionality.

As it can be seen in the screenshot, all the namespace of my whitebox are exposed just like with esxcli command. Now we are going to get the network connections of the host.

Finally following is the syntax to get the network connections of an ESXi 5 server.

In both cases I used the Format-Table cmdlet to get the ouput in a easily readable and useful format.

Juanma.

Retrieving ESX(i) hardware info with PowerCLI

We all know how to look for the basic hardware info of an ESX(i) server, just open the vSphere Client go to the Summary tab and you will presented with the familiar summary screen that includes General section with the Manufacturer, Model, etc.

We can also enter the Configuration tab and get a bit more detailed information for each hardware component.

But why we have to enter a graphical interface in order to get several pieces of information from different areas of the GUI when we can have all that information just a few commands away if we use PowerCLI for the task.

[vSphere PowerCLI] C:\Users\jreypo> $bl46001 = Get-VMHost esxbl460-01
[vSphere PowerCLI] C:\Users\jreypo>
[vSphere PowerCLI] C:\Users\jreypo> $viewbl460 = Get-View $bl46001.Id
[vSphere PowerCLI] C:\Users\jreypo> $viewbl460.Summary
[vSphere PowerCLI] C:\Users\jreypo> $viewbl460.Summary.Hardware

Vendor               : HP
Model                : ProLiant BL460c G7
Uuid                 : 36303332-3531-435a-4a30-333931304b4c
OtherIdentifyingInfo :
MemorySize           : 103067881472
CpuModel             : Intel(R) Xeon(R) CPU           X5670  @ 2.93GHz
CpuMhz               : 2933
NumCpuPkgs           : 2
NumCpuCores          : 12
NumCpuThreads        : 24
NumNics              : 8
NumHBAs              : 3
DynamicType          :
DynamicProperty      :

[vSphere PowerCLI] C:\Users\jreypo>

Oh yes! I love PowerCLI :-)

Juanma.

Managing your vSphere cluster configuration with PowerCLI

June 6, 2011 1 comment

Managing VMware vSphere cluster configuration with the vSphere Client can be, sometimes, a tedious task. In this post I’ll show you how to use PowerCLI to manage your cluster’s configuration. I did not pretend to write a full detailed guide but just to show the most common tasks I perform at work.

The first thing  to do is to properly setup the basics that will allow us to interact with the cluster. First get your cluster basic configuration and store it in a variable, $cldl380 in the example.

[vSphere PowerCLI] C:\> $cldl380 = get-cluster cluster-dl380-01

Use the cmdlet to Get-View to get the .Net objects of the cluster and store the result in another variable.

[vSphere PowerCLI] C:\> $viewdl380 = get-view $cldl380.Id
[vSphere PowerCLI] C:\> $viewdl380

Configuration       : VMware.Vim.ClusterConfigInfo
Recommendation      : {}
DrsRecommendation   : {}
MigrationHistory    : {}
ActionHistory       : {}
DrsFault            : {}
ResourcePool        : ResourcePool-resgroup-36
Host                : {HostSystem-host-37, HostSystem-host-39}
Datastore           : {Datastore-datastore-11, Datastore-datastore-12, Datastore-datastore-13, Datastore-datastore-38...}
Network             : {Network-network-21, Network-network-60, Network-network-22, Network-network-16}
Summary             : VMware.Vim.ClusterComputeResourceSummary
EnvironmentBrowser  : EnvironmentBrowser-envbrowser-35
ConfigurationEx     : VMware.Vim.ClusterConfigInfoEx
Parent              : Folder-group-h4
CustomValue         : {}
OverallStatus       : red
ConfigStatus        : red
ConfigIssue         : {0, 0}
EffectiveRole       : {-1}
Permission          : {}
Name                : cluster-dl380-01
DisabledMethod      : {}
RecentTask          : {}
DeclaredAlarmState  : {alarm-1.domain-c35, alarm-11.domain-c35, alarm-12.domain-c35, alarm-13.domain-c35...}
TriggeredAlarmState : {alarm-37.host-37, alarm-37.host-39}
AlarmActionsEnabled : True
Tag                 : {}
Value               : {}
AvailableField      : {}
MoRef               : ClusterComputeResource-domain-c35
Client              : VMware.Vim.VimClient

[vSphere PowerCLI] C:\>

This variable is the base we are going to use to get the cluster configuration, now we are going to use it.

- Get the cluster resources summary:

[vSphere PowerCLI] C:\> $viewdl380.Summary

CurrentFailoverLevel : 0
AdmissionControlInfo : VMware.Vim.ClusterFailoverLevelAdmissionControlInfo
NumVmotions          : 5
TargetBalance        : 200
CurrentBalance       : 16
CurrentEVCModeKey    :
TotalCpu             : 63984
TotalMemory          : 77287268352
NumCpuCores          : 24
NumCpuThreads        : 48
EffectiveCpu         : 56784
EffectiveMemory      : 62981
NumHosts             : 2
NumEffectiveHosts    : 2
OverallStatus        : red
DynamicType          :
DynamicProperty      :

[vSphere PowerCLI] C:\>

- Get VMware HA configuration:

[vSphere PowerCLI] C:\> $viewdl380.Configuration

DasConfig       : VMware.Vim.ClusterDasConfigInfo
DasVmConfig     :
DrsConfig       : VMware.Vim.ClusterDrsConfigInfo
DrsVmConfig     :
Rule            : {sql-cl01, hpsim}
DynamicType     :
DynamicProperty : 

[vSphere PowerCLI] C:\> $viewdl380.Configuration.DasConfig

Enabled                 : True
VmMonitoring            : vmMonitoringDisabled
HostMonitoring          : enabled
FailoverLevel           : 1
AdmissionControlPolicy  : VMware.Vim.ClusterFailoverLevelAdmissionControlPolicy
AdmissionControlEnabled : True
DefaultVmSettings       : VMware.Vim.ClusterDasVmSettings
Option                  : {das.isolationaddress1, das.isolationaddress2, das.usedefaultisolationaddress}
DynamicType             :
DynamicProperty         : 

[vSphere PowerCLI] C:\>

- Get cluster advanced options:

[vSphere PowerCLI] C:\> $viewdl380.Configuration.DasConfig.Option

Key                                   Value                                 DynamicType                          DynamicProperty                     
---                                   -----                                 -----------                          ---------------                     
das.isolationaddress1                 192.168.126.2                                                                                                     
das.isolationaddress2                 192.168.126.250                                                                                                     
das.usedefaultisolationaddress        false                                                                                                          

[vSphere PowerCLI] C:\>

- Get DRS basic configuration

[vSphere PowerCLI] C:\> $viewdl380.Configuration.DrsConfig

Enabled                   : True
EnableVmBehaviorOverrides : True
DefaultVmBehavior         : partiallyAutomated
VmotionRate               : 3
Option                    : {ForceAffinePoweron}
DynamicType               :
DynamicProperty           :

[vSphere PowerCLI] C:\> $viewdl380.Configuration.DrsConfig.Option

Key                                   Value                                 DynamicType                          DynamicProperty
---                                   -----                                 -----------                          ---------------
ForceAffinePoweron                    1

[vSphere PowerCLI] C:\>

- Get Virtual Port Groups of the cluster

[vSphere PowerCLI] C:\> Get-View $viewdl380.Network | Select-Object Name

Name
----
HeartBeatClusterSQL
iSCSI-v101
Backend-v102
Management-v105

[vSphere PowerCLI] C:\>

- Get the Datastores configured in the cluster

[vSphere PowerCLI] C:\> Get-View $viewdl380.Datastore | Select-Object Name

Name
----
FC_DS-DL380-01
FC_DS-DL380-02
iSCSI_DS-DL380-01
NFS_DS-DL380-01
LOCAL_DS-DL380-01
LOCAL_DS-DL380-02

[vSphere PowerCLI] C:\>

Finally to ease things at work I created a bunch of scripts that implement some of the above tasks, here it is an example. The syntax I used for all of them is [script-name] <cluster-name>.

# Get-ClusterAdvancedOption.ps1
# PowerCLI script to get VMware HA advanced options of a given cluster
#
# Juan Manuel Rey - juanmanuel (dot) reyportal (at) gmail (dot) com
# http://jreypo.wordpress.com
#
# Syntax: Get-ClusterAdvancedOption.ps1 <cluster-name>
#

param([string]$clustername)

$cluster = Get-Cluster $clustername
$viewcluster = Get-View $cluster.Id

$viewcluster.Configuration.DasConfig.Option

From this point I’ll leave to you to investigate all the possibilities, as always if you know a better way to do it, have any question or want to say anything about the post please comment. I’m also preparing a new post with all my small scripts and hope to publish them next week :-)

Juanma.

Reconfigure an ESX(i) for HA using vSphere PowerCLI

February 21, 2011 1 comment

Anyone with some experience and knowledge about VMware HA knows how to perform a Reconfigure for HA operation in a host from the vSphere client and I’m no exception to that rule. However I never did with PowerCLI.

I created a new cluster in my homelab with a problem in one of the hosts, I fixed the problem, put my mind to work and after an hour or so digging through PowerCLI and the vSphere API Reference Documentation I came up with the following easy way to do it.

First we are going to create a variable that contained the configuration of the ESXi I wanted to reconfigure.

C:\
[vSphere PowerCLI] % $vmhost = Get-VMHost esxi06.vjlab.local
C:\
[vSphere PowerCLI] %
C:\
[vSphere PowerCLI] % $vmhost | Format-List

State                 : Connected
ConnectionState       : Connected
PowerState            : PoweredOn
VMSwapfileDatastoreId :
VMSwapfilePolicy      : Inherit
ParentId              : ClusterComputeResource-domain-c121
IsStandalone          : False
Manufacturer          : VMware, Inc.
Model                 : VMware Virtual Platform
NumCpu                : 2
CpuTotalMhz           : 5670
CpuUsageMhz           : 869
MemoryTotalMB         : 2299
MemoryUsageMB         : 868
ProcessorType         : Intel(R) Core(TM)2 Quad CPU    Q9550  @ 2.83GHz
HyperthreadingActive  : False
TimeZone              : UTC
Version               : 4.1.0
Build                 : 260247
Parent                : cluster3
VMSwapfileDatastore   :
StorageInfo           : HostStorageSystem-storageSystem-143
NetworkInfo           : esxi06:vjlab.local
DiagnosticPartition   : mpx.vmhba1:C0:T0:L0
FirewallDefaultPolicy :
ApiVersion            : 4.1
CustomFields          : {[com.hp.proliant, ]}
ExtensionData         : VMware.Vim.HostSystem
Id                    : HostSystem-host-143
Name                  : esxi06.vjlab.local
Uid                   : /VIServer=administrator@vcenter1.vjlab.local:443/VMHost=HostSystem-host-143/

C:\
[vSphere PowerCLI] %

Next with the cmdlet Get-View I retrieved the .NET objects of the host ID and stored them in another variable.

C:\
[vSphere PowerCLI] % Get-View $vmhost.Id

Runtime             : VMware.Vim.HostRuntimeInfo
Summary             : VMware.Vim.HostListSummary
Hardware            : VMware.Vim.HostHardwareInfo
Capability          : VMware.Vim.HostCapability
ConfigManager       : VMware.Vim.HostConfigManager
Config              : VMware.Vim.HostConfigInfo
Vm                  : {}
Datastore           : {Datastore-datastore-144}
Network             : {Network-network-11}
DatastoreBrowser    : HostDatastoreBrowser-datastoreBrowser-host-143
SystemResources     : VMware.Vim.HostSystemResourceInfo
Parent              : ClusterComputeResource-domain-c121
CustomValue         : {}
OverallStatus       : red
ConfigStatus        : red
ConfigIssue         : {0}
EffectiveRole       : {-1}
Permission          : {}
Name                : esxi06.vjlab.local
DisabledMethod      : {ExitMaintenanceMode_Task, PowerUpHostFromStandBy_Task, ReconnectHost_Task}
RecentTask          : {}
DeclaredAlarmState  : {alarm-1.host-143, alarm-101.host-143, alarm-102.host-143, alarm-103.host-143...}
TriggeredAlarmState : {}
AlarmActionsEnabled : True
Tag                 : {}
Value               : {}
AvailableField      : {com.hp.proliant}
MoRef               : HostSystem-host-143
Client              : VMware.Vim.VimClient

C:\
[vSphere PowerCLI] % $esxha = Get-View $vmhost.Id

Now through the $esxha variable I invoked the method ReconfigureHostForDAS to reconfigure the ESXi, this method is part of the HostSystem object and its description can be found here in the vSphere API reference.

As it can be seen in the above screenshot, the task is displayed in the vSphere client. You can also monitor the operation with the Get-Task cmdlet.

Finally I created the below script to simplify things in the future :-)

# Reconfigure-VMHostHA.ps1
# PowerCLI script to reconfigure for VMware HA a VM Host
#
# Juan Manuel Rey - juanmanuel (dot) reyportal (at) gmail (dot) com
# http://jreypo.wordpress.com
#

param([string]$esx)

$vmhost = Get-VMHost $esx
$esxha = Get-View $vmhost.Id
$esxha.ReconfigureHostForDAS()

Juanma.

Moving hosts between datacenters with PowerCLI

February 7, 2011 Leave a comment

Today while I was setting up a new vCloud lab at home I just notice that by mistake I added one of the ESXi to the wrong cluster and in the wrong datacenter.

To be sincere, correcting this is not a big deal, just put the host in maintenance mode, get it out of the cluster and move to the correct datacenter. With the vSphere Client it can be done with a couple of clicks and a simple drag and drop. But my mistake gave me the opportunity to correct it using PowerCLI and wirte this small but hopefully useful blog post.

To explain a bit the scenario. I currently have two datacenters in my homelab, one for my day to day tests and labs and another one for vCloud Director.

1 – Put the host in maintenance mode.

To do so we re going to use the Set-VMHost cmdlet.

C:\
[vSphere PowerCLI] % Set-VMHost -VMHost vcloud-esxi1.vjlab.local -State "Maintenance"

Name            ConnectionState PowerState      Id CpuUsage CpuTotal  Memory  Memory
                                                        Mhz      Mhz UsageMB TotalMB
----            --------------- ----------      -- -------- -------- ------- -------
vcloud-esxi1... Maintenance     PoweredOn  ...t-88      126     5670     873    3071

C:\
[vSphere PowerCLI] %

2 – Move the host out of the cluster.

To perform this use the Move-VMHost cmdlet.

C:\
[vSphere PowerCLI] % Move-VMHost -VMHost vcloud-esxi1.vjlab.local -Destination vjlab-dc

Name            ConnectionState PowerState      Id CpuUsage CpuTotal  Memory  Memory
                                                        Mhz      Mhz UsageMB TotalMB
----            --------------- ----------      -- -------- -------- ------- -------
vcloud-esxi1... Maintenance     PoweredOn  ...t-88       92     5670     870    3071

C:\
[vSphere PowerCLI] %

If you check now the vSphere Client will see the host out of the cluster but still in the same datacenter.

3 – Move the host to the correct datacenter.

Now that our host is in maintenance mode and out of the cluster it is time to move it to the correct datacenter. Again we will use Move-VMHost.

C:\
[vSphere PowerCLI] % Move-VMHost -VMHost vcloud-esxi1.vjlab.local -Destination vjlab-vcloud -Verbose
VERBOSE: 03/02/2011 22:30:39 Move-VMHost Started execution
VERBOSE: Move host 'vcloud-esxi1.vjlab.local' into 'vjlab-vcloud'.
VERBOSE: 03/02/2011 22:30:41 Move-VMHost Finished execution

Name            ConnectionState PowerState      Id CpuUsage CpuTotal  Memory  Memory
                                                        Mhz      Mhz UsageMB TotalMB
----            --------------- ----------      -- -------- -------- ------- -------
vcloud-esxi1... Maintenance     PoweredOn  ...t-88       63     5670     870    3071

C:\
[vSphere PowerCLI] %

Finally put the ESXi out of maintenance mode.

C:\
[vSphere PowerCLI] % Set-VMHost -VMHost vcloud-esxi1.vjlab.local -State Connected

Name            ConnectionState PowerState      Id CpuUsage CpuTotal  Memory  Memory
                                                        Mhz      Mhz UsageMB TotalMB
----            --------------- ----------      -- -------- -------- ------- -------
vcloud-esxi1... Connected       PoweredOn  ...t-88       98     5670     870    3071

C:\
[vSphere PowerCLI] %

Check that everything is OK with the vSphere Client and we are done.

Juanma.

Get the iSCSI iqn of an ESX(i) using vSphere PowerCLI

December 14, 2010 Leave a comment

In yesterday’s post I showed how to get the iSCSI iwn fo an ESX(i) server using the vSphere CLI from the vMA and from the root shell of an ESX itself. Today it’s turn to use PowerCLI to perform the same task.

The approach to be taken is very similar to the one we used to manage the multipathing configuration.

[vSphere PowerCLI] C:\> $h = Get-VMhost esx02.mlab.local
[vSphere PowerCLI] C:\> $hostview = Get-View $h.id
[vSphere PowerCLI] C:\> $storage = Get-View $hostview.ConfigManager.StorageSystem
[vSphere PowerCLI] C:\>
[vSphere PowerCLI] C:\> $storage.StorageDeviceInfo

HostBusAdapter              : {key-vim.host.ParallelScsiHba-vmhba0, key-vim.host.BlockHba-vmhba1, key-vim.host.BlockHba-vmhba32, key-vim.host.InternetScsiHba-vmhba33}
ScsiLun                     : {key-vim.host.ScsiLun-0005000000766d68626133323a303a30, key-vim.host.ScsiDisk-0000000000766d686261303a303a30}
ScsiTopology                : VMware.Vim.HostScsiTopology
MultipathInfo               : VMware.Vim.HostMultipathInfo
PlugStoreTopology           : VMware.Vim.HostPlugStoreTopology
SoftwareInternetScsiEnabled : True
DynamicType                 :
DynamicProperty             : 

[vSphere PowerCLI] C:\>
[vSphere PowerCLI] C:\> $storage.StorageDeviceInfo.HostBusAdapter | select IScsiName

IScsiName                                                                                                                                                               
---------                                                                                                                                                                

iqn.1998-01.com.vmware:esx02-42b0f47e                                                                                                                                    

[vSphere PowerCLI] C:\>

Juanma,

Managing the multipathing configuration with vSphere PowerCLI

December 3, 2010 Leave a comment

Getting the multipathing policy using PowerCLI is a very simple an straight-forward process that can be done with a few commands.

I test this procedure in the past with ESX/ESXi 3.5 and 4.0.

Get the multipahing policy

[vSphere PowerCLI] C:\> $h = get-vmhost esx01.mlab.local
[vSphere PowerCLI] C:\> $hostview = get-view $h.id
[vSphere PowerCLI] C:\> $storage = get-view $hostView.ConfigManager.StorageSystem
[vSphere PowerCLI] C:\> $storage.StorageDeviceInfo.MultipathInfo.lun | select ID,Path,Policy

Id → → Path → → → → Policy
-- → → ---- → → → → ------
vmhba0:0:0 → {vmhba0:0:0} → → → VMware.Vim.HostMultipathInfoFixedLogicalUnitPolicy
vmhba1:1:0 → {vmhba1:1:0, vmhba1:0:0} → VMware.Vim.HostMultipathInfoFixedLogicalUnitPolicy
vmhba1:0:5 → {vmhba1:1:5, vmhba1:0:5} VMware.Vim.HostMultipathInfoFixedLogicalUnitPolicy
vmhba1:0:1 → {vmhba1:1:1, vmhba1:0:1} → VMware.Vim.HostMultipathInfoFixedLogicalUnitPolicy
vmhba1:0:12 → {vmhba1:1:12, vmhba1:0:12} → VMware.Vim.HostMultipathInfoFixedLogicalUnitPolicy

Change the policy from fixed to round-robin

We are going to change the policy for the LUN 12.

[vSphere PowerCLI] C:\> $lunId = "vmhba1:0:12"
[vSphere PowerCLI] C:\> $storagepolicy = new-object VMware.Vim.HostMultipathInfoLogicalUnitPolicy
[vSphere PowerCLI] C:\> $storagepolicy.policy = "rr"
[vSphere PowerCLI] C:\> $storageSystem.SetMultipathLunPolicy($lunId, $policy)

Finally check the new configuration

If you look closely at the last line will see that the value has change from VMware.Vim.HostMultipathInfoFixedLogicalUnitPolicy to VMware.Vim.HostMultipathInfoLogicalUnitPolicy.

[vSphere PowerCLI] C:\> $h = get-vmhost "ESXIPAddress"
[vSphere PowerCLI] C:\> $hostview = get-view $h.id
[vSphere PowerCLI] C:\> $storage = get-view $hostView.ConfigManager.StorageSystem
[vSphere PowerCLI] C:\> $storage.StorageDeviceInfo.MultipathInfo.lun | select ID,Path,Policy

Id → → Path → → → → Policy
-- → → ---- → → → → ------
vmhba0:0:0 → {vmhba0:0:0} → → → VMware.Vim.HostMultipathInfoFixedLogicalUnitPolicy
vmhba1:1:0 → {vmhba1:1:0, vmhba1:0:0} → VMware.Vim.HostMultipathInfoFixedLogicalUnitPolicy
vmhba1:0:5 → {vmhba1:1:5, vmhba1:0:5} VMware.Vim.HostMultipathInfoFixedLogicalUnitPolicy
vmhba1:0:1 → {vmhba1:1:1, vmhba1:0:1} → VMware.Vim.HostMultipathInfoFixedLogicalUnitPolicy
vmhba1:0:12 → {vmhba1:1:12, vmhba1:0:12} → VMware.Vim.HostMultipathInfoLogicalUnitPolicy

Juanma.

Add a new NFS datastore via PowerCLI and vMA

December 1, 2010 Leave a comment

As a small follow-up to yesterday’s post about NFS shares with Openfiler in the following article I will show how to add a new datastore to an ESX server using the vMA and PowerCLI.

- vMA

From the vMA shell we are going to use the command vicfg-nas. To clarify things a bit for teh newcomers, vicfg-nas and esxcfg-nas are the same command, in fact esxcfg-nas is no more than a link to the first.

The option to create a new datastore is -a and additionally the address/hostname of teh NFS servers, the share and a label for teh new datastore must be provided.

[vi-admin@vma ~][esx01.mlab.local]$ vicfg-nas -l
No NAS datastore found
[vi-admin@vma ~][esx01.mlab.local]$ vicfg-nas -a -o openfiler.mlab.local -s /mnt/vg_nfs/lv_nfs01/nfs_datastore1 nfs_datastore1
Connecting to NAS volume: nfs_datastore1
nfs_datastore1 created and connected.
[vi-admin@vma ~][esx01.mlab.local]$

When the operation is done you can check the new datastore with vicfg-nas -l.

[vi-admin@vma ~][esx01.mlab.local]$ vicfg-nas -l
nfs_datastore1 is /mnt/vg_nfs/lv_nfs01/nfs_datastore1 from openfiler.mlab.local mounted
[vi-admin@vma ~][esx01.mlab.local]$

- PowerCLI

In the second part of the post we are going to use vSphere PowerCLI, which as you already know is a PowerShell snapin to manage vSphere/VI3 infrastructure. I will write more about PowerCLI in the since I’m very fond with it.

The cmdlet to create the new NFS datastore is New-Datastore and you must provide the ESX host, the NFS server, the path of the share and a name for the datastore. Then you can check that the new datastore has been properly added with Get-Datastore.

Juanma.

Follow

Get every new post delivered to your Inbox.

Join 197 other followers

%d bloggers like this: