Tuesday, December 4, 2012

Changing VMware ESXi 5.1 Syslog settings via PowerCLI

Here is a quick and easy method to change the syslog settings on multiple ESX hosts using PowerCLI. First connect to your VC in PowerCLI and then run the below to see your current remote syslog server on each of the ESXi Hosts:

get-vmhost | Get-VMHostAdvancedConfiguration -Name Syslog.global.logHost

After getting that information you can then push out new changes:

#Get Each Host Connected to the vC
foreach ($myHost in get-VMHost)
{
    #Display the ESXi Host that you are applying the changes to
    Write-Host '$myHost = ' $myHost

    #Set the Syslog LogHost
    Set-VMHostAdvancedConfiguration -Name Syslog.global.logHost -Value 'server.domain.com,server2.domain.com' -VMHost $myHost
  
    #Use Get-EsxCli to restart the syslog service
    $esxcli = Get-EsxCli -VMHost $myHost
    $esxcli.system.syslog.reload()

    #Open the firewall on the ESX Host to allow syslog traffic
    Get-VMHostFirewallException -Name "syslog" -VMHost $myHost | set-VMHostFirewallException -Enabled:$true
}


For more information on set-VMHostAdvancedConfiguration take a look at https://www.vmware.com/support/developer/windowstoolkit/wintk40u1/html/Set-VMHostAdvancedConfiguration.html

4 comments:

  1. Thanks Caleb,

    Exactly what I was looking for.

    ReplyDelete
  2. I'm digging through my PowerCLI reference to find how to get your first command to display the names of each host alongside these syslog setting:

    PowerCLI D:\scripts> get-vmhost | get-VMHostAdvancedConfigu
    lobal.loghost

    Name Value
    ---- -----
    Syslog.global.logHost tcp://1.1.1.1:514

    Apologies for asking such a newbie question here.

    I just want a third column showing the esxhostname.

    If I find it before anyone can post it here, I'll post it here myself to share.

    cheers,
    KC

    ReplyDelete
  3. Have you tried something along the lines of:

    foreach ($myHost in get-VMHost)
    {
    Get-VMHostAdvancedConfiguration -Name Syslog.global.logHost -VMHost $myHost
    Write-host $myHost
    }

    Alternatively you could do:
    foreach ($myHost in get-VMHost)
    {
    Get-VMHostAdvancedConfiguration -Name Syslog.global.logHost,Vpx.Vpxa.config.vpxa.hostIp -VMHost $myHost
    }
    but that will only give you the IP and not the FQDN.

    ReplyDelete