The script below enables syslog on an ESXi host (server, port, protocol) but it does not actually enable syslog in the ESXi firewall. I have searched here but somehow unable to find a script that can do that. Can someone please help improve upon this script to do that? Thank you.
Get-VMHost -PipelineVariable esx |
ForEach-Object -Process {
$sLog = @{
loghost = 'tcp://server.com:1514'
}
$esxcli = Get-EsxCli -VMHost $esx -V2
$old = $esxcli.system.syslog.config.get.Invoke()
if($esxcli.system.syslog.config.set.Invoke($sLog)){
New-Object -TypeName PSObject -Property ([ordered]@{
vCenter = ([uri]$esx.ExtensionData.Client.ServiceUrl).Host
VMHost = $esx.Name
SyslogOld = $old.RemoteHost
SyslogNew = $esxcli.system.syslog.config.get.Invoke().RemoteHost
})
}
else{
Write-Error "Syslog configuration failed on $($esx.Name)"
}
} | Export-Csv -Path "c:\file.csv" -NoTypeInformation -UseCulture