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
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
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
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)