It is time for me to reward the Communities, I have learned a lot from here silently.
I use PowerCLI ONLY to setup the syslog in all 4 vCenters, tested working as well.
#Configure-SyslogOnMultipleESXiHostsIinMultiplevCenters.ps1
$Transcript = "$env:USERPROFILE\documents\transcriptForSyslogSettingChanges_$(Get-Date -format yyyy-MM-dd-hh).txt"
$vcenters = "vctrp01.vsphere.local","vctrp02.vsphere.local","vctrp03.vsphere.local","vctrp04.vsphere.local"
Start-Transcript -path $Transcript -append
Foreach ($vcenter in $vcenters){
Write-Host "Connectint to $vCenter ......" -ForegroundColor Cyan
Connect-VIServer -Server $vcenter -User $creds.User -Password $creds.Password
Write-Host "Processing the ESXi host from $vcenter" -ForegroundColor Green
$vmhosts = get-vmhost
Foreach ($vmhost in $vmhosts){
Write-Host "Processing the ESXi host $vmhost from $vcenter" -ForegroundColor Cyan
#Comment out line either udp or tcp to fit with your environment
Get-VMHost $vmhost | Get-AdvancedSetting -Name Syslog.Global.Loghost | Set-AdvancedSetting -Value udp://10.115.20.100:514 -Confirm:$false
Get-VMHost $vmhost | Get-AdvancedSetting -Name Syslog.Global.Loghost | Set-AdvancedSetting -Value tcp://10.115.20.100:514 -Confirm:$false
}
Write-Host "Disconnect from $vCenter " -ForegroundColor Yellow
Disconnect-viserver * -confirm:$false
}
Stop-Transcript
Write-Host "All done successfully, please review the result $Transcript " -ForegroundColor Yellow