VMware Cloud Community
JFitchVMA
Enthusiast
Enthusiast
Jump to solution

Enable Syslog with PowerCLI

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.

Jonathon Fitch blog: atangledweb.net Virtualization enthusiast and advocate
Reply
0 Kudos
1 Solution

Accepted Solutions
vlife201110141
Enthusiast
Enthusiast
Jump to solution

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

View solution in original post

Reply
0 Kudos
3 Replies
LucD
Leadership
Leadership
Jump to solution

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

vlife201110141
Enthusiast
Enthusiast
Jump to solution

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

Reply
0 Kudos
vlife201110141
Enthusiast
Enthusiast
Jump to solution

$loghost = "server"

or IP address of server

Reply
0 Kudos