HiperLogic

Virtualization, High Performance Computing, Enterprise Computing

Scripting

You are currently browsing the archive for the Scripting category.

Veeam Backup has an option to write the last backup time to a vCenter attribute. This is a nice feature that enables anyone using the VMware VIC client to see the last time a VM was backed up.

This feature makes it easy to write a script to ensure all VMs are backed up by querying this attribute with PowerCLI. Veeam emails you the status of all VMs it knows about ( that are in backup jobs ), but it is possible someone could add a VM that does not get added to your existing Veeam backup jobs.

The script to check for this issue is below.

1. Modify the script below to have the name of your vCenter server in $vCenterServer
2. Configure your Veeam Backup job to write to the “Backup” attribute on completion ( The default is Notes attribute, which is often used by Admins for other items ).
3. This script assumes that every VM is backed up at least once a day.
4. Run this script at the PowerCLI command prompt. See this 5 minute guide to PowerCLI to get started.

function get-backedup ($vm)
{
# This should be one line
$val = $vm.CustomFields |where {$_.key -eq "Backup" } | select -Property Value
$today = Get-Date -Format "M/d/yyyy"
$backupDate = $val.Value

return ( $backupDate -like "*$today*" )

}

Connect-VIServer $vCenterServer 

$vms = get-vm
foreach ($vm in $vms)
{
  if (get-backedup($vm)) {
      write-host -foregroundcolor green "$vm is backed up"
  } else {
      write-host -foregroundcolor red "$vm is NOT backed up"
  }
}

Tags: ,

To configure syslog on ESXi to forward to a central logger, you can just use the VIC and go to Configuration->Advanced Setting->Syslog ->Remote.

To do this on a bunch of ESXi servers, you will want to do this programatically using either the vSphere vCLI (Perl) or PowerCLI (Power Shell). Get these tools free at http://www.vmware.com/go/sysadmintools.

In the vCLI :

vicfg-syslog.pl –p 514 –s < IP of your syslog server > –server < IP of your ESXi host>

Then enter root username, and root password of your ESXi host.

In Power Shell:

Set-VMHostSysLogServer -SysLogServerPort 514 –SysLogServer < IP of your syslog sever > -VMHost < IP of your ESXi host >

Update 6/23/2010 : See this website for caveat with syslog on ESXi http://www.virtuallyghetto.com/2010/06/esxi-syslog-caveat.html

Tags:

PowerShell is a fantastic way to automate just about everything in a Windows and VMware environment, enabling your IT department to do with more with less, which is the must-have skill of today.

Unix aficionados switching to PowerShell may at first struggle with how to recreate their favorite functionality from Unix land, like grep and awk. PowerShell can do all the powerful string manipulations that awk/sed/perl can do, just in a different manner.

For example, a typical Linux scenario using awk and grep might be:

grep “somestring” foo.txt | awk ‘{print $2}’

The powershell equivalent is below:

select-string -pattern “somestring” foo.txt | foreach { $_.ToString().split(” “)[2] }

The very excellent PowerShell Community Extensions also provide some nice items you may desire from Unix/Linux toolbox.

Tags: ,

A customer requested to have a a quick and dirty script copied from d:\scripts to c:\temp and executed across a few hundred XP boxes ( not a cluster in this case ). Just in case you are looking to do this:

For %%a in (10.2.0.1 10.2.0.2 10.2.03) do start Robocopy d:\scripts\ \\%%a\C$\temp /e
psexec @hostlist c:\temp\doit.bat

© 2006-2010 HiperLogic, LLC.  |  Serving the Ann Arbor, Southeast Michigan, and Ohio region  |  (888)-268-3930  |