#Import-Module VMware.VimAutomation.Core
#如果使用 6.5.0 之前版本,需要先导入模块
Connect-VIServer -Server 192.168.1.1
#连接vCenter
$selectedlocation="Datacenter"
$AllInfo = @()
foreach ($VMHost in $VMHostlist){
#Get-VMHost $VMHost | Get-VMHostNetwork | Set-VMHostNetwork -DnsAddress $nameserver1,$nameserver2 -Domainname $domainname -SearchDomain $sdomainname
$tmpinfo=Get-VMHost $VMHost | Get-VMHostNetwork
$Info = "" | Select VMHost, Hostname, DomainName,SearchDomain,DNS
$Info.VMHost=$VMHost
$Info.Hostname=$tmpinfo.HostName
$Info.DomainName=$tmpinfo.DomainName
$Info.SearchDomain=[string]$tmpinfo.SearchDomain
$Info.DNS=[string]$tmpinfo.DnsAddress
$AllInfo += $Info
}
$Allinfo | ft -AutoSize
$AllInfo |Export-Csv hostname-$selectedlocation.csv