调用下面的函数时,它不会在“ Windows PowerShell控制台”上显示输出,但在“ Windows Powershell ISE”上可以显示输出。
Function DNSSearchOrders{
$Computer = $env:computername
$Networks = Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter IPEnabled=TRUE -ComputerName $Computer
$DNSServers = $Networks.DNSServerSearchOrder
$NetworkName = $Networks.Description
$PrimaryDNSServer = $DNSServers[0]
$SecondaryDNSServer = $DNSServers[1]
$TertiaryDNSServer = $DNSServers[2]
$OutputObj = @()
$NewObj = New-Object -Type PSObject
$NewObj | Add-Member -MemberType NoteProperty -Name Domain -Value $Computer.ToUpper()
$NewObj | Add-Member -MemberType NoteProperty -Name PrimaryDNSServers -Value $PrimaryDNSServer
$NewObj | Add-Member -MemberType NoteProperty -Name SecondaryDNSServers -Value $SecondaryDNSServer
$NewObj | Add-Member -MemberType NoteProperty -Name TertiaryDNSServers -Value $TertiaryDNSServer
$OutputObj += $NewObj
$NewObj = New-Object -Type PSObject
$NewObj | Add-Member -MemberType NoteProperty -Name Domain -Value contoso.com
$NewObj | Add-Member -MemberType NoteProperty -Name PrimaryDNSServers -Value 111.111.88.88
$NewObj | Add-Member -MemberType NoteProperty -Name SecondaryDNSServers -Value 222.333.444.88
$NewObj| Add-Member -MemberType NoteProperty -Name TertiaryDNSServers -Value "DC IP Address"
$OutputObj += $NewObj
$OutputObj
}
DNSSearchOrders