VMware Cloud Community
ivanunnio
Enthusiast
Enthusiast
Jump to solution

How to Export one list of more vCenter for farm.

Hi, I wrote a script that salted in a file the list of hosts esxi with the NTP server ip addresses.

But I saw that in the wire there are hundreds of ESXi, how can I add the name of the Virtual Center? before the hostname dell'ESXi?

Thanks so much.

# Inserire il Virtual Center desiderato
$hosts = @(
    "VC01.domain"
    "VC02.domain"
    "VC03.domain"
"VC04.domain"
"VC05.domain"
"VC06.domain"
"VC07.domain"
"VC08.domain"
"VC09.domain"
"VC010.domain"
"VC011.domain"
"VC012.domain"
"VC013.domain"
);


# Mi collego al VC sopra descritto nella prima riga
Connect-VIServer $hosts -User $user -Password $password #-SaveCredentials

# Definisco la variabile globale
$VMHosts = Get-VMHost

# Stampo in un file il risultato della ricerca.
Get-VMHost | Select-Object Name,@{Name=”NTPServer”;Expression={$_ | Get-VMHostNtpServer}}, @{Name=”NTPRunning”;Expression={($_ | Get-VMHostService | Where-Object {$_.key -eq “ntpd”}).Running}} | Sort-Object -Property “NTPRunning”, “NTPServer” | Export-Csv -NoTypeInformation -Path ("C:\scripts\" + "Estrazione_NTP_Horizon6" + "_" + $((get-date).ToString("dd.MM.yyyy-HHmm"))+ ".csv" )

# forzo la disconnessione dal Virtual Center Server
Disconnect-VIServer $hosts -force -confirm:$false

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try like this

$hosts = @(

    "VC01.domain"

    "VC02.domain"

    "VC03.domain"

"VC04.domain"

"VC05.domain"

"VC06.domain"

"VC07.domain"

"VC08.domain"

"VC09.domain"

"VC010.domain"

"VC011.domain"

"VC012.domain"

"VC013.domain"

);

# Mi collego al VC sopra descritto nella prima riga

Connect-VIServer $hosts -User $user -Password $password #-SaveCredentials

# Definisco la variabile globale

$VMHosts = Get-VMHost

# Stampo in un file il risultato della ricerca.

Get-VMHost | Select-Object Name,

    @{N='vCenter';E={$_.Uid.Split('@')[1].Split(':')[0]}},

    @{Name=”NTPServer”;Expression={$_ | Get-VMHostNtpServer}},

    @{Name=”NTPRunning”;Expression={($_ | Get-VMHostService | Where-Object {$_.key -eq “ntpd”}).Running}} | Sort-Object -Property “NTPRunning”, “NTPServer” |

Export-Csv -NoTypeInformation -Path ("C:\scripts\" + "Estrazione_NTP_Horizon6" + "_" + $((get-date).ToString("dd.MM.yyyy-HHmm"))+ ".csv" )

# forzo la disconnessione dal Virtual Center Server

Disconnect-VIServer $hosts -force -confirm:$false


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

View solution in original post

Reply
0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

Try like this

$hosts = @(

    "VC01.domain"

    "VC02.domain"

    "VC03.domain"

"VC04.domain"

"VC05.domain"

"VC06.domain"

"VC07.domain"

"VC08.domain"

"VC09.domain"

"VC010.domain"

"VC011.domain"

"VC012.domain"

"VC013.domain"

);

# Mi collego al VC sopra descritto nella prima riga

Connect-VIServer $hosts -User $user -Password $password #-SaveCredentials

# Definisco la variabile globale

$VMHosts = Get-VMHost

# Stampo in un file il risultato della ricerca.

Get-VMHost | Select-Object Name,

    @{N='vCenter';E={$_.Uid.Split('@')[1].Split(':')[0]}},

    @{Name=”NTPServer”;Expression={$_ | Get-VMHostNtpServer}},

    @{Name=”NTPRunning”;Expression={($_ | Get-VMHostService | Where-Object {$_.key -eq “ntpd”}).Running}} | Sort-Object -Property “NTPRunning”, “NTPServer” |

Export-Csv -NoTypeInformation -Path ("C:\scripts\" + "Estrazione_NTP_Horizon6" + "_" + $((get-date).ToString("dd.MM.yyyy-HHmm"))+ ".csv" )

# forzo la disconnessione dal Virtual Center Server

Disconnect-VIServer $hosts -force -confirm:$false


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

Reply
0 Kudos
ivanunnio
Enthusiast
Enthusiast
Jump to solution

Hi LUCD

Thank you so much for your support if you really precious, your edit works perfectly, but I was now generating an identical script but I have to generate a report that gives me only the ESXi server DNS. How can I integrate it?

I'm must integrate this classe, inside one alone script

Get-VMHost | Get-VMHostNetwork | Select Hostname, DNSAddress | Select Hostname, DNSAddress

Get-VMHost | Select-Object Name, @{N='vCenter';E={$_.Uid.Split('@')[1].Split(':')[0]}

each line works but I can not do a mix for (Host ESXi, Venter, DNS)

Reply
0 Kudos