- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you @LucD . I was able to add that to the script and it worked, however the export had empty rows. Also, I believe a reload command is needed after updating the syslog server and port, and also the syslog ESXi firewall to prevent having to reboot. So I added more lines to the script. I am currently getting the following error when I run it, and I have tried various things but am still getting similar errors:
At line:29 char:3
+ $esxcli.network.firewall.refresh.Invoke(@{rulesetid='syslog'; ...
+ ~~~~~~~
Missing closing ')' after expression in 'if' statement.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : MissingEndParenthesisAfterStatementBelow is the script. I basically want it to perform the reloads I mentioned above, and also if possible, export the new firewall ruleset value as well. Thanks.
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()
$old2 = $esxcli.network.firewall.ruleset.list.Invoke(@{rulesetid='syslog'})
if($esxcli.system.syslog.config.set.Invoke($sLog)){
$esxcli.system.syslog.reload.invoke($sLog)
if(($esxcli.network.firewall.ruleset.set.Invoke(@{rulesetid='syslog'; enabled=$true}))
$esxcli.network.firewall.refresh.Invoke(@{rulesetid='syslog'; enabled=$true})
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
FirewallRulesetNew = $esxcli.network.firewall.ruleset.list.Invoke(@{rulesetid='syslog'}).RemoteHost
})
}
}
else{
Write-Error "Syslog configuration failed on $($esx.Name)"
} | Export-Csv -Path "c:\file.csv" -NoTypeInformation -UseCulture