Configuring syslog for esxi hosts

After installation of vmware syslog server you can point your esx/i boxes to log directly to that server. But in the ‘data’ directory from syslog collector you will see instead of hostnames, ips of your host systems. I wanted to show how to create easier to read version of this directory.
By the way if you want to configure multiple hosts to log to syslog server you can use below line:

get-cluster 'your_cluster'|get-vmhost| Set-VMHostAdvancedConfiguration -NameValue @{'Config.HostAgent.log.level'='info';'Vpx.Vpxa.config.log.level'='info';'Syslog.global.logHost'='udp://syslogip:514'}

or to change settings for all hosts within the VC.

get-vmhost| Set-VMHostAdvancedConfiguration -NameValue @{'Config.HostAgent.log.level'='info';'Vpx.Vpxa.config.log.level'='info';'Syslog.global.logHost'='udp://syslogip:514'}

You may want not to override your settings for logging level, in that case delete those settings with logging level and leave only the logHost.

Also you probably want to change firewall settings in order to allow this traffic:

get-cluster 'yourcluster'|get-vmhost| Get-VMHostFirewallException |?{$_.Name -eq 'syslog'} | Set-VMHostFirewallException -Enabled:$true

or to change it for all hosts in VC

get-vmhost| Get-VMHostFirewallException |?{$_.Name -eq 'syslog'} | Set-VMHostFirewallException -Enabled:$true

And the script:

function createshortcut{
param ( [string]$linkloc, [string]$DestPath )

$WshShell = New-Object -comObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut($linkloc)
$Shortcut.TargetPath = $DestPath
$Shortcut.Save()
}

$collectordir="d:\Syslog Collector\data\"
$collectordirwithnames="d:\HostLogs\"
foreach($dir in Get-ChildItem $collectordir|where { $_.PSIsContainer } ){
$vmhostname=[System.Net.Dns]::GetHostByAddress($dir.name).Hostname
createshortcut "${collectordirwithnames}${vmhostname}.lnk" $dir.fullname
}

So, define your directory where your logs are written in $collectordir, then define second directory where you would like to keep the ‘human readable’ shortcuts to those directories. You will have to create this directory manually first. Then What this script will do, it will go to the data directory, read all directories(which are ips of your esx/i boxes), assuming they are all registered within dns, he will get their hostnames, and create links to those directories. Links names instead of ips, will consist of hosts hostnames. If you have 2-3 esx you probably know their ips 😉 But if you have 100..1000 or 10000 😉 Then it’s bit harder to recognize which is which. I hope that will help 😉

VMware vCenter Operations Manager Fundamentals [V5.X] Free course

If you have VC Operations in your infrastructure and you would like learn more, there is a free e-learning course at:
http://mylearn.vmware.com/mgrreg/courses.cfm?ui=www_edu&a=det&id_course=132265

• Technical Overview of vCenter Operations Manager covers the vCenter Operations Manager 5.0 vApp architecture and resource requirements, the vCenter Operations Manager 5.0 vApp installation considerations, and introduces you to the major and minor badges.

• Installing and Configuring vCenter Operations Manager discusses how to install and configure vCenter Operations Manager.

• Using the Dashboards and Badges explains the main function of the major and minor badges, how to interpret the badge results, and how to configure thresholds and notifications.

• Operations and Planning describes how to use the Operations tab and the Planning tab.

• Working with Smart Alerts and Reports covers how to configure and use smart alerts, how heat maps are used, and how to work with reports.

I think it’s worth to enroll. Not only it is created by VMware, but it is free. AND WE ALL LOVE FREE STUFF !!!!!!!!!!!!! 😉

Amazing connection, powercli + vsphere cli

Now that was a very very very good post from Robert. You can check this post and his blog at
http://rvdnieuwendijk.com/2011/07/21/how-to-run-vmware-vsphere-cli-perl-scripts-from-powercli/
Once you create this function ‘Add-vCLIfunction’ and run it, you can easly run ‘functions’ from vSphere CLI. This is very very very useful.
All of those perl scripts from vsphere cli will become available for us like a function. Well we can just now simply type ‘vifs’ and bam! One thing worth mentioning here, it does not do the ‘powercli’ ‘powershell’ style output 😉 don’t forget about this, this is not an object. Basically we are still executing perl scripts, so the output is just simple text. But still you receive functions from vSphere CLI.
$a=vicfg-nics -l –server myHost1
$a|get-member -> string[]
Quick example:
I want to download quickly hostd.log from esx box
vifs –server myHost.Local -g /host/hostd.log c:\hostd.log
All sorts of things using vifs:
http://blogs.vmware.com/vsphere/2012/06/using-vclis-vifs-for-more-than-just-datastore-file-management-.html#more

Check host advanced settings using powercli

I wanted to check settings for NFS that i have in place for all hosts in specific cluster.
Here is what i came up with:

get-cluster 'myCluster' | get-vmhost | %{ $hostn=$_.Name; Get-VMHostAdvancedConfiguration -VMHost $_ | % { $_.getEnumerator()| ? {$_.Key -like "NFS*"}|select Name,Value,@{N='host';E={$hostn}} }  } | export-csv c:\nfssettings.csv
----Output before sending to export-csv
Name                            Value host
----                            ----- ----
NFS.WorldletAffinity            x     host1
NFS.VolumeRemountFrequency      y     host1
NFS.LockUpdateTimeout           z     host1
NFS.LogNfsStat3                 y     host2

In nfssettings.csv you will have nice table with nfs_setting_name , value, and host name from which it was taken.
What’s with the $_.GetEnumerator() ?, right, so when you will run

Get-VMHostAdvancedConfiguration -vmhost "your_host" | gm

You will notice that we are receiving hashtable. Since this is hashtable we can not fitler it with just simple where,select as this comes as a 1 BIG table. It looks like it consists of rows etc etc… so you would think that those are several objects, but at the end it is just like 1 big hashtable 😉 So we want to have ability to go through each element in this hashtable to search only for those with key similar to NFS*. Obviously if you want to search for other things like NFS, then put the proper name instead of NFS.

Get-VMHostAdvancedConfiguration -vmhost "your_host"
(Get-VMHostAdvancedConfiguration -vmhost "your_host").GetEnumerator()

Although they output is the same, when you are using GetEnumerator it is possible for you to do select with where-object.
Instead of receiving object type of hashtable, we are receiving now multiple System.Collections.DictionaryEntry which have Key and Value property. That’s why now we can use Where-Object to seek for your NFS settings.Since we are querying all host systems within cluster i want to have also a column with host name so that’s why i had to do $hostn=$_.Name; in the loop. To store the host name because this information would be lost in next pipeline.

Checking vmkernel interfaces using get-vmhostnetworkadapter in specific portgroup name

If you have labeled vmkernel portgroups using names such as vmotion, nfs that would describe the purpose we can quickly search ip of those cards.

Get-VMHostNetworkAdapter -VMKernel -VMHost (get-cluster "myCluster1"|get-vmhost)  | ? {$_.PortgroupName -eq "nfs"} | select Name,VMhost,Mac,IP
Name         VMHost              Mac                        IP
----         ------              ---                        --
vmk1         host1               00:50:56:77:77:77          192.168.0.10
vmk1         host2               00:50:56:77:77:78          192.168.0.20

Nice, we now have mac,ip vmkernel interface name and information in which host in the cluster this vmk resides.
Now, if you want to get additional information besides those, you can try to check which are available by yourself.
So the object we are investigating here is a vmhostnetworkadapter.
Let’s take 1 vmhostnetworkadapter first:

Get-VMHost MyHost1 | Get-VMHostNetworkAdapter -VMKernel | ? {$_.PortgroupName -eq "nfs"}  | gm

You can see the | gm at the end. This will help us investigate what other properties are available to us.
First we will notice that the object type is:

TypeName: VMware.VimAutomation.ViCore.Impl.V1.Host.Networking.Nic.HostVMKernelVirtualNicImpl

And we will receive whole list of properties and methods that are available

Name                         MemberType
----                         ----------
ConvertToVersion             Method
Equals                       Method
GetHashCode                  Method
GetType                      Method
IsConvertableTo              Method
ToString                     Method
AutomaticIPv6                Property
DeviceName                   Property
DhcpEnabled                  Property
ExtensionData                Property
FaultToleranceLoggingEnabled Property
Id                           Property
IP                           Property
IPv6                         Property
IPv6Enabled                  Property
IPv6ThroughDhcp              Property
Mac                          Property
ManagementTrafficEnabled     Property
Mtu                          Property
Name                         Property
PortGroupName                Property
SubnetMask                   Property
Uid                          Property
VMHost                       Property
VMHostId                     Property
VMHostUid                    Property
VMotionEnabled               Property

If we want to check only properties of this object we could specify this in get-mamber so:

Get-VMHost MyHost1 | Get-VMHostNetworkAdapter -VMKernel | ? {$_.PortgroupName -eq "nfs"}  | get-member -MemberType Property

For those who got lost a little with gm … get-member
gm does exactly the same as get-member. If you will type
alias gm
you will receive information that in fact this is just an alias for get-member

CommandType     Name       Definition
-----------     ----       ----------
Alias           gm         Get-Member

Alright, back to the main topic.
So what else can we get from the VMHostNetworkAdapter. By now we should see what kind of properties are there. You can add them to the select-object command

Get-VMHostNetworkAdapter -VMKernel -VMHost (get-cluster "myCluster1"|get-vmhost)  | ? {$_.PortgroupName -eq "nfs"} | select Name,VMhost,Mac,IP ->here

So if you wanted to see for example SubnetMask or Mtu you would just simply add it at the end to select-object like this

Get-VMHostNetworkAdapter -VMKernel -VMHost (get-cluster "myCluster1"|get-vmhost)  | ? {$_.PortgroupName -eq "nfs"} | select Name,VMhost,Mac,IP,Mtu,SubnetMask

Let’s say we want to see EVERYTHING that is available for us right away:

Get-VMHostNetworkAdapter -VMKernel -VMHost (get-cluster "myCluster1"|get-vmhost)  | ? {$_.PortgroupName -eq "nfs"} | select *
Get-VMHostNetworkAdapter -VMKernel -VMHost (get-cluster "myCluster1"|get-vmhost)  | ? {$_.PortgroupName -eq "nfs"} | format-list *
Get-VMHostNetworkAdapter -VMKernel -VMHost (get-cluster "myCluster1"|get-vmhost)  | ? {$_.PortgroupName -eq "nfs"} | format-table *

As you can see you can query all those properties in different ways.
One more thing, ‘select’ is an alias for Select-Object.
Format-list will generate output in a list as the name suggests 😉
Format-Table will generate a table (you have possibility to configure the table style here)
Select-Object will try to generate a ‘table look’, but it will not be the same table as format-table does. What is worth mentioning here is that for example object that will come from Format-Table or Format-List will not be understood by export-csv. Format-table output looks pretty much the same as if you had used the select-object, but it has different type. In this case only output from select-object could be piped without error to export-csv.
Whenever you are wondering if you can have more information about some object simply use get-member on it. If this will be a VM object, a VMHostNetworkAdapter object or a host object, you always can use get-member to see if there are useful properties for you to check.

Managing all esx ssh connections at the same time with putty connection manager

You can download putty connection manager from here:
http://www.thegeekstuff.com/scripts/puttycm.zip
You will be able to connect to all of your esx/i boxes and using the “Command section” issue the command to run on all of the opened sessions.
You can use cssh under linux for example and putty cm under windows.
For example if you want to check all registered vms on all of those esx boxes simply put
“vim-cmd /vmsvc/getallvms”
in the command section. It will invoke this command on all esx boxes.
Short post this time, but there not much to add.

Managing services on esxi host systems from powercli, starting tsm-ssh

What if you wanted to check status of some particular service on the host system. For example, you need to login via ssh to all of your esxi boxes in myCluster1.
Let’s check status of remote Tech support ssh service

Get-Cluster -Name "myCluster1" | get-vmhost | Get-VMHostService | ? {$_.Key -eq "TSM-ssh"}
Key                  Label                          Policy     Running  Required
---                  -----                          ------     -------  --------
TSM-SSH              Remote-Support (SSH)           off        True     False
TSM-SSH              Remote-Support (SSH)           off        False    False
TSM-SSH              Remote-Support (SSH)           off        False    False

This is the default output. We do not see on which host the ssh is turned on or off
We can quickly add it to our output:

Get-Cluster -Name "myCluster1" | get-vmhost | % {$vhost=$_.name; get-VMHostSErvice -VMHost $_ | ? {$_.Key -eq "TSM-ssh"}|select @{N="Host";E={$vhost}}, @{N="Service";E={$_.Key}},Running,Policy }

Host                   Service        Running Policy
----                   -------        ------- ------
host1                  TSM-SSH          True off
host2                  TSM-SSH          True off
host3                  TSM-SSH          True off

Above line will do what is needed, but i just realized that this not efficient as there is no need to do this approach. VMhost property is included in each service object. So we can just simply use below line.

Get-Cluster -Name "UPCAT WIN CLuster" | get-vmhost | Get-VMHostService | ? {($_.Key -eq "TSM-ssh")} |select VMHost, Key,Label, Running

To check what servieces are avaialable on host :

get-vmhost "vmhost1" |Get-VMHostService|select Key,Label

Now if you want to start for example TSM-SSH service, for all hosts in cluster

Get-Cluster -Name "myCluster1" | get-vmhost | Get-VMHostService | ? {($_.Key -eq "TSM-ssh") -and ($_.Running -eq $False)} | Start-VMHostService

So we are looking for tesm-ssh services wich are not currently running and piping them to Start-VMHostSErvice.

As you can see it is very easy to manipulate host system services from powercli.