PowerCLI: Reconfigure for vSphere HA


Sometimes when you change something to the vSphere HA configuration like an Advanced Option, you have to reconfigure vSphere HA on each host inside that particular cluster. You can do that by hand via the Reconfigure for vSphere HA.. option inside the vSphere (Web) Client:

Screenshot 2016-01-22 13.11.47

Or you can use the following PowerCLI one-liner to perform this step on every host inside that cluster.

Get-Cluster <clusterName | Get-VMhost | Sort Name | %{$_.ExtensionData.ReconfigureHostForDAS()}

Just change the to the name of the cluster en open PowerCLI, connect to the vCenter server and run the one-liner.

PowerCLI: Get-VirtualPortgroup -Distributed VlandId value is empty


Today I was busy with PowerCLI and dvPort groups.  I started to use the Get-VirtualPortgroup –Distributed cmdlet and parameter to retrieve some information about the dvPort group. But the default output doesn’t show the VlanId. See the screen shot below for the default output.

image

I don’t know if this is a known issue between PowerCLI 5.1 release 1 and vSphere 4.1 update 2. So I have to test it in a vSphere 5 environment.

But how can you find the vlanid of a distributed portgroup? You can use a PowerCLI script which I created  to fix this little “bug” and I have also added the PortsFree column to the output of the script.

$dvPortgroup = get-virtualportgroup -Distributed -Name "vlan1"
$dvPortgroupInfo = New-Object PSObject -Property @{            
    Name = $dvPortgroup.Name
    Key = $dvPortgroup.Key
    VlanId = $dvPortgroup.ExtensionData.Config.DefaultPortConfig.Vlan.VlanId
    Portbinding = $dvPortgroup.Portbinding
    NumPorts = $dvPortgroup.NumPorts
    PortsFree = ($dvPortgroup.ExtensionData.PortKeys.count - $dvPortgroup.ExtensionData.vm.count)
}  
$dvPortgroupInfo | ft -AutoSize

The output of the script:

image

If you want to create a report of all the dvPort groups. You can use the following script to achieve that goal:

$info = @()
foreach($dvPortgroup in (Get-VirtualPortgroup -Distributed | Sort Name)){
    $dvPortgroupInfo = New-Object PSObject -Property @{            
        Name = $dvPortgroup.Name
        Key = $dvPortgroup.Key
        VlanId = $dvPortgroup.ExtensionData.Config.DefaultPortConfig.Vlan.VlanId
        Portbinding = $dvPortgroup.Portbinding
        NumPorts = $dvPortgroup.NumPorts
        PortsFree = ($dvPortgroup.ExtensionData.PortKeys.count - $dvPortgroup.ExtensionData.vm.count)
    }  
    $info += $dvPortgroupInfo
}
$info | Export-Csv -UseCulture -NoTypeInformation C:\tmp\dvportgroup_info.csv

Host Profiles: Ruleset xxxx doesn’t match the specification


Today I was testing Host Profiles (again) and I must say it works a lot better than during my previous tests. There was only one thing very annoying during my tests. When the host was in maintenance mode, I applied the Host Profile and performed a check. Everything was OK and the host was compliant.  But when the host was out Maintenance mode and I checked if the host was still compliant, I received the following message:

image

Unfortunately there’s no knowledgebase article which describes those messages so I started to Google and found a post on the VMware Communites by khushal: http://communities.vmware.com/message/1357268

1. Open vCenter go to Home — > Management –> Host Profiles

2. Right Click on the Host Profile you are using for your Cluster and Select Edit

3. Expand the profile Profile

– Profile-name

– Firewall configuration

*     – Ruleset Configuration*

*     – faultTolerance*

       Select Ruleset and check the checkbox in right hand “*Flag Indicating whether ruleset should be enabled”

Click OK.

and check Compliance again in Cluster.

To fix the annoying messages I did change the aam and faultTolerance settings via:

Continue reading

Troubleshoot TCP connection issues from the ESX Service Console


If you need to troubleshoot TCP connection issues from your ESX host. You will notice that Telnet isn’t available on your ESX host. But VMware posted a workaround in KB1010747. The reason why VMware did not include the Telnet package is simple:

The TELNET package does not ship with the ESX service console. While the TELNET daemon is clearly a security risk, the TELNET client may be a useful tool in diagnosing TCP session connectivity between the ESX Service Console and TCP ports on a foreign host.

The workaround is a Python script. You can copy the following script to your ESX host and place it in /tmp directory.

#!/usr/bin/python
# TCP connection "tester" -
# provide the hostname/IP address followed by port number (if no port
# is specified, 23 is assumed ;)
# program will connect to the port and read till either it receives a
# newline or 5 seconds expire
# be sure to chmod 755
import sys
import telnetlib
import socket

PORT = ""
argc = len(sys.argv)

if argc == 3 :
    PORT = sys.argv[2]
elif argc < 2 or argc > 3:
    print "usage %s host <port> \n" % sys.argv[0]
    sys.exit()

HOST = sys.argv[1]

try:
    tn = telnetlib.Telnet(HOST,PORT)
except socket.error, (errno, strerror):
    print " SockerError( %s ) %s\n" %  (errno, strerror)
    sys.exit()

print tn.read_until("\n ",5)
print "connection succeeded\n"
tn.close()
sys.exit()

If you want to test if a particular TCP port is reachable from your ESX host. You can use the script like this:

[root@esx01 ~]# ./testtcp vc01.ict-freak.loc 443

connection succeeded

[root@esx01 ~]#

In case the TCP port is not reachable from your ESX host. The script will just hang on your command and will eventually time out:

[root@esx01 ~]# ./testtcp vc01.ict-freak.loc 443
SockerError( 110 ) Connection timed out

You can also cancel the script by pressing CTRL + C

I didn’t test the script from ESXi. If you did, please leave a comment.

Source: KB1010747

PowerCLI: Return the iSCSI Software Adapter


In my previous postsabout how to manage iSCSI targets with PowerCLI part 1 and part 2. I used the following line to return the iSCSI adapter:

$hba = $esx | Get-VMHostHba -Type iScsi

But when I used this line against a vSphere 4.1 update 1 host with Broadcom BCM5709 (Dell Poweredge R710). vSphere will use these adapters as Broadcom iSCSI Adapters. And when you run the $hba = $esx | Get-VMHostHba -Type iScsi one-liner, it will return all the vmhba adapters.

[vSphere PowerCLI] C:\> $esx | Get-VMHostHba -Type iScsi

Device     Type         Model                          Status

——     —-         —–                          ——

vmhba32    IScsi        Broadcom iSCSI Adapter         unbound

vmhba33    IScsi        Broadcom iSCSI Adapter         unbound

vmhba34    IScsi        Broadcom iSCSI Adapter         unbound

vmhba35    IScsi        Broadcom iSCSI Adapter         unbound

vmhba37    IScsi        iSCSI Software Adapter            online

This “problem” can easily be resolved with a Where statement. In the following Where statement you look for a Model that equals “iSCSI Software Adapter”. There is only one Software adapter in ESX(i) so it will return the right vmhba. The PowerCLI line will look like this:

$esx | Get-VMHostHba -Type iScsi | Where {$_.Model -eq "iSCSI Software Adapter"} 

[vSphere PowerCLI] C:\> $esx | Get-VMHostHba -Type iScsi | Where {$_.Model -eq "iSCSI Software Adapter"}

Device     Type         Model                          Status

——     —-         —–                          ——

vmhba37    IScsi        iSCSI Software Adapter         online

So the bottom line. Test your code on different setups and update it when necessary 😉

Storage vMotion only one hard disk to another datastore in vSphere


Sometimes it’s necessary to only migrate a single hard disk from a VM. This is the case when someone adds two 1 TB VMDK’s and fills them up completely. The maximum size of a VMFS datastore is 2TB minus 512 bytes. So in this case the datastore will be completely filled with no space left to keep the VM running. So if you want  to migrate just one hard disk to make sure the VMFS datastore will not fill up. You can use the vSphere client or PowerCLI to do perform this “advanced” Storage vMotion.

Note: if you want to reclaim your “wasted” storage back from your SAN, you have to recycle the whole datastore. So you have to migrate the other hard disks and configuration files as well.

vSphere Client

Start the Migrate Virtual Machine wizard and select datastore:

image

Continue reading

PowerCLI: Host Networking Device info


In this post I will share a simple PowerCLI script which generates some Network Device information from your vSphere hosts. The information you’ll get is the vmHost name, device name, linkspeed and MAC address.

$vmHostNicInfo = @()
foreach($vmHost in (Get-VMHost | Sort Name)){
    foreach($nic in $vmhost.NetworkInfo.PhysicalNic){ 
        $Details = "" | Select vmHost, Device,Linkspeed,Mac

        $Details.vmHost = $vmhost.Name
        $Details.Device = $nic.Extensiondata.Device
        $Details.Linkspeed = ($nic.Extensiondata.Linkspeed).SpeedMB
        $Details.Mac = $nic.Extensiondata.Mac
    
        $vmHostNicInfo += $Details
    }
}
$vmHostNicInfo | Format-Table -AutoSize

The output will look like this:image

But what if you only want to see the devices with a link speed lower then 1000? Well that’s possible with the following end line:

$vmHostNicInfo | Where {$_.Linkspeed -lt "1000"} |  Format-Table -AutoSize

image

Or if you want to know which device/host belongs to a particular MAC address. You can use the following end line:

$vmHostNicInfo | Where {$_.Mac -eq "00:07:e9:1f:f9:bf"} |  Format-Table -AutoSize

image

So with a small script, you’re able to export valuable data.

Review: PHD Virtual Backup


Before I start with this post I first want to welcome a new sponsor: PHD Virtual.

                                             

In this post I will be doing a short review, sponsored by PHD, of the latest version of PHD backup. In this post I will show the following topics:

  1. install the PHD Virtual Backup Console and Plug-in
  2. Deploy OVF template of the PHD Virtual Backup Appliance
  3. Configure the PHD Virtual Backup Appliance
  4. Add VMs to a Backup job
  5. Restore a complete VM
  6. Restore individual Files
  7. Conclusion

So let’s start with the installation.

Continue reading

PowerCLI: Easy NFS datastore setup


It’s a new year so let’s start with a new PowerCLI post. This post is inspired by the blog post of @alanrenouf: PowerCLI easy vswitch portgroup setup. I love the whole idea of taking a good working config from a vSphere host and use it on a fresh installed vSphere host to make sure it’s compliant.  In this post I will show you how to perform the same trick with NFS datastores like Alan did with the vSwithes and Portgroups.

My home lab contains two HP ml110 g5 and a simple P4 box with some hard disks to add shared storage to the lab. It’s running Debian linux and is capable of presenting iSCSI targets, NFS and SAMBA shares .I use NFS as shared storage for my vSphere lab.

On esx2.ict-freak.local I use the following NFS datastores:

image

But I messed up the configuration of the other vSphere host in my lab called esx1.ict-freak.local. So I had to reset the network settings and lost all the NFS datastores:

image

So I needed to add the five NFS shares. This is a nice task for PowerCLI and the New-Datastore cmdlet:

Update: I had to remove the last / from the Path variable. If you do not remove the last / the script will mount the NFS share but with a new UUID. See Damian Karlson his post about this subject here.

Continue reading

vMotion error: Virtual machine must be running in order to be migrated


Today I wanted to Storage vMotion a VM to a new datastore. But for the first time I got a general error message:

image

followed up by a general system error message:

image

I got the same message when I tried to start a “normal” vMotion. So I start to troubleshoot this error. First I looked at the vmware.log of the VM. Nothing unusual in there. So the next stop was the VMkernel. But there was nothing unusual in it too. So I used the good old Microsoft like fix to restart the VMware services at the Service Console using the following command:

service mgmt-vmware restart

after a minute or so I was able to start a vMotion again and after the vMotion completed I started the storage vMotion I was planning to do and this worked like a charm again.

To recap. Sometimes you need to restart the mgmt-vmware to fix the connection between the vSphere host and vCenter.