jlkumar07
Contributor
Contributor

Esxi host config settings

HI LucD,

      i am trying to host configuration settings to .csv file but getting some of them are empty but when run them individually exporting the results are fine.  please help to export the result of host config(some shown below script ) to .csv file

$vihosts =Get-Cluster "cluster" | Get-VMHost

$report=

forEach ($vhost in $vihosts){

$esxcli = Get-VMhost $vhost | Get-Esxcli

$esxcli.network.firewall.ruleset.list() | Where {$_.Name -eq "iSCSI"} | Select @{N="VMHost";E={$ESXCLI.VMHost}}, Name, Enabled

$esxcli.network.firewall.ruleset.list() | Where {$_.Name -eq "CIMHttpServer"} | Select @{N="VMHost";E={$ESXCLI.VMHost}}, Name, Enabled

$esxcli.network.firewall.ruleset.list() | Where {$_.Name -eq "snmp"} | Select @{N="VMHost";E={$ESXCLI.VMHost}}, Name, Enabled

$esxcli.network.firewall.ruleset.list() | Where {$_.Name -eq "ftpClient"} | Select @{N="VMHost";E={$ESXCLI.VMHost}}, Name, Enabled

$esxcli.network.firewall.ruleset.list() | Where {$_.Name -eq "nfsClient"} | Select @{N="VMHost";E={$ESXCLI.VMHost}}, Name, Enabled

$esxcli.system.snmp.get()|Select @{N="VMHost";E={$ESXCLI.VMHost}}, enable, port

Get-VMHost $vhost |Sort Name|Select Name, @{N=“NTPServer“;E={$_ |Get-VMHostNtpServer}}, @{N=“ServiceRunning“;E={(Get-VmHostService -VMHost $_ |Where-Object {$_.key-eq “ntpd“}).Running}}

Get-VMHostService -VMHost $vhost | Where {$_.key –eq "TSM"} | select Key, Running, VMHost

Get-VMHostService -VMHost $vhost | Where {$_.key –eq "TSM-SSH" } | select Key, Running, VMHost

Get-VMHostService -VMHost $vhost | Where {$_.key –eq "DCUI"} | select Key, Running, VMHost

Get-vmhost $vhost | Get-AdvancedSetting -Name Syslog.loggers.syslog.size | select Value, Entity, Name

Get-vmhost $vhost | Get-AdvancedSetting -Name Syslog.loggers.syslog.rotate| select Value, Entity, Name

Get-vmhost $vhost | Get-AdvancedSetting -Name Syslog.global.logHost| select Value, Entity, Name

Get-VMHost $vhost | Get-AdvancedSetting -Name UserVars.ESXiShellTimeout| select Value, Entity, Name

Get-VMHost $vhost | Get-AdvancedSetting -Name Syslog.global.logDirUnique| select Value, Entity, Name

Get-vmhost $vhost | select Name,@{N="LockDown";E={$_.Extensiondata.Config.adminDisabled}}

Get-vmhost $vhost | Select Name,@{N="Net.DVFilterBindIpAddress";E={$_ | Get-AdvancedSetting Net.DVFilterBindIpAddress | Select -ExpandProperty Values}}

Get-vmhost $vhost | Get-VMHostHba | Where {$_.Type -eq “iSCSI”} | Select VMHost, Device, ChapType, @{N=”CHAPName”;E={$_.AuthenticationProperties.ChapName}}

}$report | export-csv C:\Tempfile\hostconfig.csv -notypeinformation

0 Kudos
1 Reply
LucD
Leadership
Leadership

Try something like this.

Note that due to the inner loop of the iSCSI HBA there will be a lot of redundant information in the resulting CSV

$report = forEach ($vhost in (Get-Cluster "cluster" | Get-VMHost | Sort-Object -Property Name)){

    $esxcli = Get-Esxcli -VMHost $vmhost

    $services = Get-VMHostService -VMHost $vhost

    $advanced = Get-AdvancedSetting -Entity $vhost

    $fw = $esxcli.network.firewall.ruleset.list()

    $snmp = $esxcli.system.snmp.get()

    foreach($iscsi in (Get-VMHostHba -VMHost $vhost -Type IScsi)){

        $vmhost | Select Name,

            @{N=“NTPServer“;E={$_ |Get-VMHostNtpServer}},

            @{N=“NTPServiceRunning“;E={($services | Where-Object {$_.key-eq “ntpd“}).Running}},

            @{N='TSM';E={$services | Where {$_.key –eq "TSM"} | Select -ExpandProperty Running}},

            @{N='TSM';E={$services | Where {$_.key –eq "TSM-SSH"} | Select -ExpandProperty Running}},

            @{N='TSM';E={$services | Where {$_.key –eq "DCUI"} | Select -ExpandProperty Running}},

            @{N='Syslog.loggers.syslog.size';E={$advanced | where{$_.Name -eq 'Syslog.loggers.syslog.size'} | select -ExpandProperty Value}},

            @{N='Syslog.loggers.syslog.rotate';E={$advanced | where{$_.Name -eq 'Syslog.loggers.syslog.rotate'} | select -ExpandProperty Value}},

            @{N='Syslog.global.logHost';E={$advanced | where{$_.Name -eq 'Syslog.global.logHost'} | select -ExpandProperty Value}},

            @{N='UserVars.ESXiShellTimeout';E={$advanced | where{$_.Name -eq 'UserVars.ESXiShellTimeout'} | select -ExpandProperty Value}},

            @{N='Syslog.global.logDirUnique';E={$advanced | where{$_.Name -eq 'Syslog.global.logDirUnique'} | select -ExpandProperty Value}},

            @{N='FW iSCSI';E={$fw | where {$_.Name -eq "iSCSI"} | select -ExpandProperty Enabled}},

            @{N='FW CIMHttpServer';E={$fw | where {$_.Name -eq "CIMHttpServer"} | select -ExpandProperty Enabled}},

            @{N='FW SNMP';E={$fw | where {$_.Name -eq "snmp"} | select -ExpandProperty Enabled}},

            @{N='FW ftpClient';E={$fw | where {$_.Name -eq "ftpClient"} | select -ExpandProperty Enabled}},

            @{N='FW nfsClient';E={$fw | where {$_.Name -eq "nfsClient"} | select -ExpandProperty Enabled}},

            @{N='SNMP Enable';E={$snmp | select -ExpandProperty Enable}},

            @{N='SNMP Port';E={$snmp | select -ExpandProperty Port}},

            @{N="LockDown";E={$_.Extensiondata.Config.adminDisabled}},

            @{N="Net.DVFilterBindIpAddress";E={$_ | Get-AdvancedSetting Net.DVFilterBindIpAddress | Select -ExpandProperty Values}},

            @{N='iSCSI Device';E={$iscsi.Device}},

            @{N='iSCSI ChapType';E={$iscsi.ChapType}},

            @{N='iSCSI ChapName';E={$iscsi.AuthenticationProperties.ChapName}}

    }

}

$report | export-csv C:\Tempfile\hostconfig.csv -notypeinformation


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