I’ve a customer who have several DataCenters in the vCenter and each DataCenter needs different Syslog-Server. With this script you should be able to set for each Datacenter different Syslog-Server.

#Map DC to log server:
$servermap = @{
    "DC1" = "tcp://,tcp://";
    "DC2" = "tcp://,tcp://";
    "DC3" = "tcp://,tcp://";
foreach ($vmhost in (Get-VMHost)) {
    $DC = (Get-Datacenter -VMHost $vmhost)
    echo $vmhost.Name 
    echo $servermap.($DC.Name)

    $syslog = $servermap.($DC.Name)
    Get-AdvancedSetting -Entity $vmhost -Name "SysLog.Global.loghost" | Set-AdvancedSetting -Value $syslog -Confirm:$false
    Write-Host "Restarting syslog daemon." -ForegroundColor Green
    $esxcli = Get-EsxCli -VMHost $vmhost -V2
    Write-Host "Setting firewall to allow Syslog out of $($vmhost)" -ForegroundColor Green
    Get-VMHostFirewallException -VMHost $vmhost | where {$ -eq 'syslog'} | Set-VMHostFirewallException -Enabled:$true

We hope it helps some of you.

Similar Posts