ESXi

 View Only
Expand all | Collapse all

Script to get esxi syslog location across vCenter

466kdl1

466kdl1Oct 23, 2017 09:07 PM

  • 1.  Script to get esxi syslog location across vCenter

    Posted May 12, 2017 08:47 AM

    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



  • 2.  RE: Script to get esxi syslog location across vCenter

    Posted May 12, 2017 11:15 AM

    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 }



  • 3.  RE: Script to get esxi syslog location across vCenter

    Posted Oct 12, 2017 06:20 AM

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



  • 4.  RE: Script to get esxi syslog location across vCenter

    Posted Oct 12, 2017 06:43 AM

    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



  • 5.  RE: Script to get esxi syslog location across vCenter

    Posted Oct 12, 2017 09:27 PM

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



  • 6.  RE: Script to get esxi syslog location across vCenter

    Posted Oct 12, 2017 09:35 PM

    My bad, there was a typo in there.
    I updated the code above, please try again.



  • 7.  RE: Script to get esxi syslog location across vCenter

    Posted Oct 13, 2017 09:55 AM

    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



  • 8.  RE: Script to get esxi syslog location across vCenter

    Posted Oct 13, 2017 11:38 AM

    From the error message it looks like $vcenterFQDN is empty, but the script you included doesn't have that variable.



  • 9.  RE: Script to get esxi syslog location across vCenter

    Posted Oct 16, 2017 03:30 AM

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



  • 10.  RE: Script to get esxi syslog location across vCenter

    Posted Oct 16, 2017 04:34 AM

    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?



  • 11.  RE: Script to get esxi syslog location across vCenter

    Broadcom Employee
    Posted Oct 16, 2017 09:33 AM

    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



  • 12.  RE: Script to get esxi syslog location across vCenter

    Posted Oct 16, 2017 10:25 AM

    Thank you Jterli,

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



  • 13.  RE: Script to get esxi syslog location across vCenter

    Posted Oct 16, 2017 10:55 AM

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



  • 14.  RE: Script to get esxi syslog location across vCenter

    Posted Oct 16, 2017 11:24 AM

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



  • 15.  RE: Script to get esxi syslog location across vCenter

    Posted Oct 16, 2017 11:38 AM

    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

    }



  • 16.  RE: Script to get esxi syslog location across vCenter

    Posted Oct 17, 2017 04:39 AM

    Thank you very much script is running fine.



  • 17.  RE: Script to get esxi syslog location across vCenter

    Broadcom Employee
    Posted Oct 17, 2017 06:34 AM

    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



  • 18.  RE: Script to get esxi syslog location across vCenter

    Posted May 13, 2017 09:34 AM

    Try like this

    Get-VMHost -PipelineVariable esx | Get-VMHostSysLogServer |

    Select @{N='VMHost';E={$esx.Name}},

        @{N='SyslogServer';E={$_.Host,$_.Port -join ':'}}



  • 19.  RE: Script to get esxi syslog location across vCenter

    Posted Oct 23, 2017 09:07 PM

    Thank you.