Hi All,
Need to update esxi syslog location across my vCenters. Is there a script which can get me the existing syslog location of all the esxi host across my vCenters.
Thanks in Advance
Hi,
Pls connect to the vCenter and run this code. It will return the syslog servers configured in each Hyps.
Get-VMHost | % {
$hostName = $_.name
$_ | Get-VMHostSysLogServer | select @{N="ESXiHostName";E={$hostname} }, Host }
Try like this
Get-VMHost -PipelineVariable esx | Get-VMHostSysLogServer |
Select @{N='VMHost';E={$esx.Name}},
@{N='SyslogServer';E={$_.Host,$_.Port -join ':'}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
This is working fine but how to get to excel sheet with information.
Did you try like this?
Get-VMHost -PipelineVariable esx | Get-VMHostSysLogServer |
Select @{N='VMHost';E={$esx.Name}},
@{N='SyslogServer';E={$_.Host,$_.Port -join ':'}} |
Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
thanks for immediate reply. But am not getting host list in the sheet. Vmhost showing empty in the excel sheet.
My bad, there was a typo in there.
I updated the code above, please try again.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Super......... it is working for me now. thanks much.
Do you have other script to push snmp servers in to all esxi hosts in the environment.
I have below script but it is getting errors.:
$esxlist = Import-Csv "C:\scritp\servers.txt"
foreach($item in $esxlist){
Connect-VIServer $item
-User root -Password
$item| Set-VMHostSnmp -Enabled:$true
Set-VMHostSnmp
-HostSnmp $_ -ReadOnlyCommunity "Name" -TargetHost "xxxxx"
Disconnect-VIServer -Confirm:$false
From the error message it looks like $vcenterFQDN is empty, but the script you included doesn't have that variable.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Can you please help to me on SNMP script m new to scripting . Thanks you in advance.
The error messages you included do not seem to correspond with the script you included.
Can you include the correct code, or the correct error messages?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
The below script may help you.
Check the following before executing the script :
1. The "servers.txt" file path is correct
2. Each server name in the "servers.txt" file should be in a new line.
Script :
$esx_list = Get-Content -Path "C:\scritp\servers.txt"
foreach ($item in $esx_list) {
Connect-VIServer -Server $item -User root -Password "password"
Get-VMHostSnmp | Set-VMHostSnmp -Enabled:$true -ReadOnlyCommunity "Name" -TargetHost "xxxxx"
}
Disconnect-VIServer * -Confirm:$false
Thank you Jterli,
As suggested I have tried above code but getting some different error ;
If you use the TargetHost parameter, you have to add the AddTarget switch as well.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Sorry LucD, I did't get you can can you suggested for the same.
The Set-VMHostSnmp cmdlet has 4 different parameter sets.
The one that was picked has a number of required parameters, and you have to specify all of them.
The script becomes
$esx_list = Get-Content -Path "C:\scritp\servers.txt"
foreach ($item in $esx_list) {
Connect-VIServer -Server $item -User root -Password "password"
Get-VMHostSnmp | Set-VMHostSnmp -Enabled:$true -TargetCommunity "Name" -TargetHost "xxxxx" -AddTarget
Disconnect-VIServer -Server $item -Confirm:$false
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thank you very much script is running fine.
My Mistake, missed to add the "-AddTarget" switch
$esx_list = Get-Content -Path "C:\Users\Administrator\Documents\PowerCliScripts\servers.txt"
foreach ($item in $esx_list) {
Connect-VIServer -Server $item -User root -Password 'ca$hc0w'
Get-VMHostSnmp | Set-VMHostSnmp -Enabled:$true -ReadOnlyCommunity test -AddTarget -TargetHost "x.x.x.x" -TargetCommunity Public
}
Disconnect-VIServer * -Confirm:$false
Thank you.