AlbertWT
Virtuoso
Virtuoso

Combining the PowerCLI result for NTP and DNS server to .CSV file ?

Jump to solution

Hi All,

I wonder if it is possible to combine the below two PowerCLI line so the exported result can be in .CSV format ?

Get-VMHost | Sort Name | Select Name, @{N="NTP";E={Get-VMHostNtpServer $_}}

Get-VMHost | Get-VMHostNetwork

Thanks in advance.

/* Any kind of comment or input would be greatly appreciated */
1 Solution

Accepted Solutions
mattboren
Expert
Expert

Hello, -

It sure is! You can get those properties in a single returned object per VMHost like:

Get-VMHost | Get-VMHostNetwork | Select HostName, DomainName, DnsFromDhcp, `

      ConsoleGateway, ConsoleGatewayDevice, DnsAddress, @{N="NTP";E={Get-VMHostNtpServer $_.VMHost}}

That should give you some goodness like (example for one server):

HostName             : myesxi02

DomainName           : mydom.com

DnsFromDhcp          : False

ConsoleGateway       :

ConsoleGatewayDevice :

DnsAddress           : {172.16.0.13, 172.16.0.16, 8.8.4.4}

NTP                  : pool.ntp.org

Then, to export that to CSV, you just pipe all of that to Export-CSV, of course (add " | Export-Csv c:\temp\myFile.csv -NoTypeInformation" to the end of the line, without the quotes).  That do it for you?

View solution in original post

2 Replies
mattboren
Expert
Expert

Hello, -

It sure is! You can get those properties in a single returned object per VMHost like:

Get-VMHost | Get-VMHostNetwork | Select HostName, DomainName, DnsFromDhcp, `

      ConsoleGateway, ConsoleGatewayDevice, DnsAddress, @{N="NTP";E={Get-VMHostNtpServer $_.VMHost}}

That should give you some goodness like (example for one server):

HostName             : myesxi02

DomainName           : mydom.com

DnsFromDhcp          : False

ConsoleGateway       :

ConsoleGatewayDevice :

DnsAddress           : {172.16.0.13, 172.16.0.16, 8.8.4.4}

NTP                  : pool.ntp.org

Then, to export that to CSV, you just pipe all of that to Export-CSV, of course (add " | Export-Csv c:\temp\myFile.csv -NoTypeInformation" to the end of the line, without the quotes).  That do it for you?

View solution in original post

AlbertWT
Virtuoso
Virtuoso

mattboren,

Cool, many thanks for the quick reply.

Yes it works.

Why does the ConsoleGateway and ConsoleGatewayDevice property is always blank ?

/* Any kind of comment or input would be greatly appreciated */
0 Kudos