Add second VMKernel interface to multiple ESXi hosts

I have to add a VMKernel interface for NAS traffic to a series of hosts that I just built. I am going to call the portgroup NAS as that is the purpose. The portgroup will be in vSwitch0 along with the MGMT network.

These are the commands I need

esxcli network vswitch standard portgroup add -p NAS -v vSwitch0
esxcfg-vmknic -a -i a.b.c.d -n 255.255.255.0 -p NAS
esxcli network ip interface  set -i vmk1 -m 9000    

But I need to run this through a series of hosts. I place the hostnames and IPs in a file in this format. Continue reading

Advertisements

Configure hostname for multiple ESXi hosts

I build a bunch of new ESXi hosts and this is how I configure hostname for each host.

First, I have the list of the hosts’ FQDN in a file

$ cat list
esxi01.example.com
esxi02.example.com
esxi03.example.com
esxi04.example.com
esxi05.example.com
esxi06.example.com

I use cat and awk to generate an ssh command for each host. This assumes you have ssh keys configured. Continue reading

Collecting directly connected switch ports ID from multiple ESXi hosts

We are going to add vlan to a cluster. We need to know what are the switch ports for each Guest vmnic in each hosts so that we can ask the network team to trunk the new vlan.

This little script collects the switch ports information obtained using CDP. The list of hosts is stored in a text file list.

    for i in `cat list`
    do
    ssh -q -T root@$i <<EOF
    hostname
    vim-cmd hostsvc/net/query_networkhint --pnic-name=vmnicX  | grep -E  'devId|portId'
    vim-cmd hostsvc/net/query_networkhint --pnic-name=vmnicY  | grep -E  'devId|portId'
    echo
    EOF
    done

In this example, vmnicX and vmnicY are used for Guest network. If you don't have ssh keys setup, you can use sshpass.

    host1.esx.example.com
             devId = "SwitchA",
             portId = "Ethernet110/1/2",
             devId = "SwitchB",
             portId = "Ethernet110/1/2",

    host2.esx.example.com
             devId = "SwitchA",
             portId = "Ethernet110/1/4",
             devId = "SwitchB",
             portId = "Ethernet110/1/4",

    host3.esx.example.com
             devId = "SwitchA",
             portId = "Ethernet110/1/6",
             devId = "SwitchB",
             portId = "Ethernet110/1/6",

    ... and so on

Assign permission to a list of VMs using PowerCLI

Copy the list of VMs to a file C:\vmlist.txt.

$vmlist = Get-Content C:\vmlist.txt
foreach ($i in $vmlist)
{
Get-VM -Name $i | New-VIPermission -Role "ROLE_NAME" -Principal "Domain\GROUP"
OR
Get-VM -Name $i | New-VIPermission -Role "ROLE_NAME" -Principal "Domain\USER"
}

To verify

$vmlist = Get-Content C:\vmlist.txt
foreach ($i in $vmlist)
{
Get-VM -Name $i | Get-VIPermission | Where-Object {$_.Role -like "ROLE_NAME*"}
}