I've written the following script to pull a list of hosts that already have some existing syslog servers configured and to add a new one however i keep getting the error "Unable to configure syslog server information for host 'xxx.xx.xxx'..... InnerText: No Root object set for output. The command did not provide proper output.implementation error!"
Any idea where i have gone wrong?
function ConfigureSyslog {
Write-Host
$txtlocation = Read-Host " Please enter txt file location"
write-host
write-host " Syslog server format UDP://X.X.X.X:514" -ForegroundColor Yellow
$SyslogServer = Read-Host " Please enter syslog server"
$GlobalSysLogConfig = @()
ForEach ($esxhost in (Get-Content $txtlocation))
{
if((Get-VMHost $esxhost | Get-VMHostSysLogServer).Host -notcontains "$SyslogServer"){
$EsxSysLogConfig = "" | select Host, Config, Time, Change
Write-Host ".... Writing existing configuration of host $esxhost to log" -ForegroundColor Green
$EsxSysLogConfig.Host = (Get-VMHost $esxhost).Name
$EsxSysLogConfig.Config = (Get-VMHost $esxhost | Get-VMHostSysLogServer)
$EsxSysLogConfig.Time = $(get-date -f yyyy-MM-dd-hhmm)
$EsxSysLogConfig.Change = "Existing"
$GlobalSysLogConfig += $EsxSysLogConfig
$CombineConfig = $EsxSysLogConfig.Config +$SyslogServer
Write-Host ".... Adding $SyslogServer to configuration on host $esxhost" -ForegroundColor Green
Get-VMHost $esxhost | Set-VMHostSysLogServer -SysLogServer "$CombineConfig" -Confirm:$false
$EsxSysLogConfig.Host = (Get-VMHost $esxhost).Name
$EsxSysLogConfig.Config = (Get-VMHost $esxhost | Get-VMHostSysLogServer)
$EsxSysLogConfig.Time = $(get-date -f yyyy-MM-dd-hhmm)
$EsxSysLogConfig.Change = "Changed"
$GlobalSysLogConfig += $EsxSysLogConfig
}
else{
Get-VMHost $host | Get-VMHostSysLogServer | export-csv -path ".\Syslog Config.csv" -append
Write-Host "$esxhost is already configured with $SyslogServer, moving on..." -ForegroundColor Red
Start-Sleep -Second 1
$EsxSysLogConfig.Host = (Get-VMHost $esxhost).Name
$EsxSysLogConfig.Config = (Get-VMHost $esxhost | Get-VMHostSysLogServer)
$EsxSysLogConfig.Time = $(get-date -f yyyy-MM-dd-hhmm)
$EsxSysLogConfig.Change = "No Change"
$GlobalSysLogConfig += $EsxSysLogConfig
}
$GlobalSysLogConfig | Export-CSV Filename ".\Syslog $(get-date -f yyyy-MM-dd-hhmm).csv"
}
}
write-host
$VCChoice = Read-Host " Please enter vCenter Name"
Connect-VIServer $VCChoice
ConfigureSyslog
Change this line:
Get-VMHost $esxhost | Set-VMHostSysLogServer -SysLogServer "$CombineConfig" -Confirm:$false
to:
Get-VMHost $esxhost | Set-VMHostSysLogServer -SysLogServer $SyslogServer -Confirm:$false
That specific error has been mentioned before.
There were a number of possible reasons:
- name resolution for the syslog server was not working on the ESXi node
- the connection to the remote syslog server was not working
- the local syslog folder was incorrect (for example a disconnected LUN).
Update: I found an older reference to that same error.
See Solved: Cannot set Syslog.global.logHost either by GUI or ... - VMware Technology Network VMTN
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
If I don't use $CombineConfig, it removes the existing configuration. I can try $CombineConfig without the quotation marks though?
quotation marks do not make a difference here. What LucD mentioned might be the reason.
Or
try this $CombineConfig = "$EsxSysLogConfig.Config,$SyslogServer"