Highlighted
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
Highlighted
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 }

0 Kudos
Highlighted
User Moderator
User Moderator

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

Highlighted
Enthusiast
Enthusiast

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

0 Kudos
Highlighted
User Moderator
User Moderator

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

Highlighted
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

0 Kudos
Highlighted
User Moderator
User Moderator

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

0 Kudos
Highlighted
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

0 Kudos
Highlighted
User Moderator
User Moderator

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

0 Kudos
Highlighted
Enthusiast
Enthusiast

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

0 Kudos
Highlighted
User Moderator
User Moderator

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

0 Kudos
Highlighted
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

0 Kudos
Highlighted
Enthusiast
Enthusiast

Thank you Jterli,

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

pastedImage_0.png

0 Kudos
Highlighted
User Moderator
User Moderator

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


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

0 Kudos
Highlighted
Enthusiast
Enthusiast

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

0 Kudos
Highlighted
User Moderator
User Moderator

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

0 Kudos
Highlighted
Enthusiast
Enthusiast

Thank you very much script is running fine.

0 Kudos
Highlighted
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

0 Kudos
Highlighted
Enthusiast
Enthusiast

Thank you.

0 Kudos