I'm trying to enable the syslog service through the ESXi 5 firewall and configure the syslog server info with a small script that hits all hosts at one time but I can't seem to find the combination that will allow it to work. What I am trying is:
Get-VMHost | select name | Set-VMHostSysLogServer -SysLogServer server:514
When I run that it tells me that the requireed parameter -VMHost is missing. Is there a way to apply this setting to all hosts in a given vCenter? I'd also like to enable the firewall rules for syslog in a similar manner.
I wrote this one and it works without problem so far. If you dont want to change $defaultrotate and $defaultrotaesize then change the line below to
$esxclisetsyslog = $esxcli.system.syslog.config.set($null, $null, $null, $null, $loghost, $null)
Connect-VIServer -Server "vcenterserver" -User "xxx" -Password "xxx"
[long]$defaultrotate = 16
[long]$defaultrotatesize = 10240
$loghost = "x.x.x.x"
$esxhosts = Get-VMHost
foreach($esx in $esxhosts){
$hview = Get-View -ViewType "hostsystem" -Filter @{"Name"= $esx.Name}
# ------- HostImageConfigGetAcceptance -------
$_this = Get-View -Id $hview.ConfigManager.ImageConfigManager
$_this.HostImageConfigGetAcceptance()
# ------- EnableRuleset -------
$_this = Get-View -Id $hview.ConfigManager.FirewallSystem
$_this.EnableRuleset("syslog")
# ------- ESXCLI enable syslog -------
$esxcli = Get-EsxCli -vmhost $esx.Name
$esxclisetsyslog = $esxcli.system.syslog.config.set($defaultrotate, $defaultrotatesize, $null, $null, $loghost, $null)
$esxcli.system.syslog.reload()
}
Disconnect-VIServer -Server "vcenterserver" -Confirm:$false
Leave out the Select cmdlet.
Get-VMHost | Set-VMHostSysLogServer -SysLogServer server:514
To enable the FW rule on all hosts you can do
Get-VMHost | Get-VMHostFirewallException | where {$_.Name -eq "syslog"} |
Set-VMHostFirewallException -Enabled $true -Confirm:$false
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I wrote this one and it works without problem so far. If you dont want to change $defaultrotate and $defaultrotaesize then change the line below to
$esxclisetsyslog = $esxcli.system.syslog.config.set($null, $null, $null, $null, $loghost, $null)
Connect-VIServer -Server "vcenterserver" -User "xxx" -Password "xxx"
[long]$defaultrotate = 16
[long]$defaultrotatesize = 10240
$loghost = "x.x.x.x"
$esxhosts = Get-VMHost
foreach($esx in $esxhosts){
$hview = Get-View -ViewType "hostsystem" -Filter @{"Name"= $esx.Name}
# ------- HostImageConfigGetAcceptance -------
$_this = Get-View -Id $hview.ConfigManager.ImageConfigManager
$_this.HostImageConfigGetAcceptance()
# ------- EnableRuleset -------
$_this = Get-View -Id $hview.ConfigManager.FirewallSystem
$_this.EnableRuleset("syslog")
# ------- ESXCLI enable syslog -------
$esxcli = Get-EsxCli -vmhost $esx.Name
$esxclisetsyslog = $esxcli.system.syslog.config.set($defaultrotate, $defaultrotatesize, $null, $null, $loghost, $null)
$esxcli.system.syslog.reload()
}
Disconnect-VIServer -Server "vcenterserver" -Confirm:$false
$loghost = "server"
or IP address of server
