Recently deployed a new syslog server and needed a script to update the ~20+ ESXi hosts as fast as possible. This is pretty cut and dry in terms of what happens… prompts for vCenter and Syslog addresses, then it updates the Syslog Server field on each host associated with that vCenter as well as allowing UDP/514 through the ESXi firewall.
1 2 3 4 5 6 7 8 9 10 11 |
$vCenterServer = Read-Host "vCenter FQDN or IP " $SyslogServer = Read-Host "Syslog Server Info (ip:port) " Connect-VIServer $vCenterServer Get-VMHost | Foreach { Write-Host "Adding Syslog server info for $($_.Name)" $SetSyslog = Set-VMHostSysLogServer -SysLogServer $SyslogServer -VMHost $_ Write-Host "Reloading Syslog service for $($_.Name)" $Reload = (Get-ESXCLI -VMHost $_).System.Syslog.reload() Write-Host "Setting firewall rules for $($_)" $FW = $_ | Get-VMHostFirewallException | Where {$_.Name -eq 'syslog'} | Set-VMHostFirewallException -Enabled:$true } |