VMware Cloud Community
RajuVCP
Hot Shot
Hot Shot

Script to get esxi syslog location across vCenter

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

Raju Gunnal VCP 4, VCP 5, VTSP 4, VTSP 5, ITIL V3 http://www.techtosolution.com
18 Replies
Sreejesh_D
Virtuoso
Virtuoso

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 }

Reply
0 Kudos
LucD
Leadership
Leadership

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

466kdl1
Enthusiast
Enthusiast

This is working fine  but how to get to excel sheet with information.

Reply
0 Kudos
LucD
Leadership
Leadership

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

466kdl1
Enthusiast
Enthusiast

thanks for immediate reply. But am not getting host list in the sheet. Vmhost showing empty in the excel sheet.

pastedImage_0.png

Reply
0 Kudos
LucD
Leadership
Leadership

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

Reply
0 Kudos
466kdl1
Enthusiast
Enthusiast

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

pastedImage_0.png

Reply
0 Kudos
LucD
Leadership
Leadership

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

Reply
0 Kudos
466kdl1
Enthusiast
Enthusiast

Can you please help to me on SNMP script m new to scripting . Thanks you in advance.

Reply
0 Kudos
LucD
Leadership
Leadership

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

Reply
0 Kudos
jterli
VMware Employee
VMware Employee

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

Reply
0 Kudos
466kdl1
Enthusiast
Enthusiast

Thank you Jterli,

As suggested I have tried above code but getting some different error ;

pastedImage_0.png

Reply
0 Kudos
LucD
Leadership
Leadership

If you use the TargetHost parameter, you have to add the AddTarget switch as well.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
466kdl1
Enthusiast
Enthusiast

Sorry LucD, I did't get you can can you suggested for the same.

Reply
0 Kudos
LucD
Leadership
Leadership

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.

target.jpg

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

Reply
0 Kudos
466kdl1
Enthusiast
Enthusiast

Thank you very much script is running fine.

Reply
0 Kudos
jterli
VMware Employee
VMware Employee

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

Reply
0 Kudos
466kdl1
Enthusiast
Enthusiast

Thank you.

Reply
0 Kudos