VMware Cloud Community
AlbertWT
Virtuoso
Virtuoso
Jump to solution

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

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.

/* Please feel free to provide any comments or input you may have. */
1 Solution

Accepted Solutions
mattboren
Expert
Expert
Jump to solution

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
Jump to solution

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?

AlbertWT
Virtuoso
Virtuoso
Jump to solution

mattboren,

Cool, many thanks for the quick reply.

Yes it works.

Why does the ConsoleGateway and ConsoleGatewayDevice property is always blank ?

/* Please feel free to provide any comments or input you may have. */
Reply
0 Kudos