How configure crontab in ESXi to schedule a job every 5 min

How configure crontab in ESXi to schedule a job every 5 min

For scheduling a command or script every 5 min in ESXi we need to edit following file

/var/spool/cron/crontabs/root

vi /var/spool/cron/crontabs/root

#min hour day mon dow command
1    1    *   *   *   /sbin/tmpwatch.py
1    *    *   *   *   /sbin/auto-backup.sh
0    *    *   *   *   /usr/lib/vmware/vmksummary/log-heartbeat.py
*/5  *    *   *   *   /sbin/hostd-probe ++group=host/vim/vmvisor/hostd-probe
00   1    *   *   *   localcli storage core device purge
*/2 * * * * /usr/lib/vmware/vsan/bin/vsanObserver.sh

Continue reading How configure crontab in ESXi to schedule a job every 5 min

VMware ESXi Datastores refresh issue incorrect free space

VMware ESXi Datastores refresh issue incorrect free space

We do manual datastore scan or HBA  scan to show the correct free space .

We can change the refresh interval manually to edit config.xml file in esxi host.

To change the refresh interval, edit the configuration file and change the refreshInterval value to the desired interval.

To change the refreshInterval value:

  1. Using a text editor, open the /etc/vmware/hostd/config.xml file on the host.
  2. Locate the <datastore> element. This element in the default file is similar to:<datastore>
    <!-- default datastore inventory-->
    <!-- <inventory>/etc/vmware/hostd/datastores.xml</inventory> -->
    <!-- default datastore refresh interval in minutes -->
    <!-- use 0 to disable the auto refresh -->
    <!-- <refreshInterval>0</refreshInterval> -->
    <!-- default datastore list refetch interval, after getting a VMFS event, in seconds-->
    <!-- <refetchVMFSDatastoreListInterval>30</refetchVMFSDatastoreListInterval> -->
    </datastore>
  3. Remove the comment indicators and replace the 0 (zero) in the <refreshInterval> element with the desired number of minutes. For example, to set the refresh interval to one hour, change this line:<!-- <refreshInterval>0</refreshInterval> -->

    to:

    <refreshInterval>60</refreshInterval>

  4. Save and close the file.
  5. Restart the hostd service for the changes to take effect.
  6. /etc/init.d/hostd restart

Continue reading VMware ESXi Datastores refresh issue incorrect free space

How to scan HBA Vmware ESXi Vmware Power CLI

How to scan HBA Vmware ESXi Vmware Power CLI

Connect to your ESX or VCenter Server

Connect-VIServer -Server 192.168.1.10  -Protocol https -User Administrator@vsphere.local -Password P@ssw0rd

To Scan all ESXi hosts is Cluster
Get-Cluster ‘cluster name‘ | Get-VMHost  | Get-VMHostStorage -RescanAllHba

To scan single ESX  host

Get-VMHost ‘192.168.1.11‘ | Get-VMHostStorage -RescanAllHba

 

How to get vms, with their current ips, macaddresses, networkcard types

How to get vms, with their current ips, macaddresses, networkcard types

Below are the script i got to get all VM name UUID, VLAN assigned, MAC address , IP address,Network card type.

Its export in CSV .

 

$reportedvms=New-Object System.Collections.ArrayList
$vms=get-view -viewtype virtualmachine  |Sort-Object -Property {  $_.Config.Hardware.Device |  where {$_ -is [VMware.Vim.VirtualEthernetCard]} |  Measure-Object | select -ExpandProperty Count} -Descending
 
foreach($vm in $vms){
  $reportedvm = New-Object PSObject
  Add-Member -Inputobject $reportedvm -MemberType noteProperty -name Guest -value $vm.Name
  Add-Member -InputObject $reportedvm -MemberType noteProperty -name UUID -value $($vm.Config.Uuid)
$networkcards=$vm.guest.net | ?{$_.DeviceConfigId -ne -1}
$i=0
foreach($ntwkcard in $networkcards){
Add-Member -InputObject $reportedvm -MemberType NoteProperty -Name "networkcard${i}.Network" -Value $ntwkcard.Network
Add-Member -InputObject $reportedvm -MemberType NoteProperty -Name "networkcard${i}.MacAddress" -Value $ntwkcard.Macaddress  
Add-Member -InputObject $reportedvm -MemberType NoteProperty -Name "networkcard${i}.IpAddress" -Value $($ntwkcard.IpAddress|?{$_ -like "*.*"})
Add-Member -InputObject $reportedvm -MemberType NoteProperty -Name "networkcard${i}.Device" -Value $(($vm.config.hardware.device|?{$_.key -eq $($ntwkcard.DeviceConfigId)}).gettype().name)
$i++
}
$reportedvms.add($reportedvm)|Out-Null
}
 
$reportedvms|Export-Csv C:\PCLITEST\inventry\networkcard.csv

 

How to Configuring an NTP Time Server on ESXi PowerCLI

How to Configuring an NTP Time Server on ESXi PowerCLI

If there are no NTP server configured

Get-VMHost esx01 | Add-VMHostNtpServer -NtpServer ntpservername

 

Or to first of all clear existing NTP server(s) then set the new one:

Get-VMHost esx01 | Remove-VMHostNtpServer -NtpServer (Get-VMHost esx01 | Get-VMHostNtpServer)
Get-VMHost esx01 | Add-VMHostNtpServer -NtpServer ntpservername

 

Source link