首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >DNSServerSearchOrder输出格式

DNSServerSearchOrder输出格式
EN

Stack Overflow用户
提问于 2018-12-12 07:42:20
回答 1查看 496关注 0票数 0

我一直在开发一个PowerShell函数来向我显示有用的信息。

我正在努力使它在没有指定参数的情况下默认为localhost,或者接受命令行参数,但这是另一个版本。我试图解决的主要问题是输出DNSServerSearchOrder。

这是我的代码。

代码语言:javascript
运行
复制
function Get-CompInf {
    $ComputerName    = "."
    $ComputerSystem  = Get-WmiObject -Class Win32_ComputerSystem -ComputerName $ComputerName
    $OperatingSystem = Get-WmiObject -Class win32_OperatingSystem -ComputerName $ComputerName
    $Bios            = Get-WmiObject -Class win32_BIOS -ComputerName $ComputerName
    $Net             = Get-WmiObject -Class Win32_NetworkAdapterConfiguration -ComputerName $ComputerName |
                       Where-Object {$_.IPConnectionMetric -ne $null}
    # DNS - *** want to fix this so it breaks to one address per line.
    $DNSstring       = Get-WmiObject -Class Win32_NetworkAdapterConfiguration -ComputerName . |
                       Where-Object {$_.IPConnectionMetric -ne $null} |
                       Select-Object -ExpandProperty DNSServerSearchOrder
    $Disk            = Get-WmiObject -Class Win32_LogicalDisk -ComputerName $ComputerName |
                       Where-Object DeviceID -eq "c:"

    # Prepare Output
    $NetInfo = [ordered]@{
        "Computer Name. . ." = $Net.PSComputerName
        "Link Speed . . . ." = (Get-NetAdapter | Where-Object status -eq "up" | Select-Object -ExpandProperty LinkSpeed)
        "MAC. . . . . . . ." = $Net.MacAddress
        "IP Address . . . ." = ($Net.IPAddress.trim("{}"))
        "Default Gateway. ." = ($Net.DefaultIPGateway.trim("{}"))
        "DHCP Server. . . ." = $Net.DHCPServer
        "DNS Servers. . . ." = $DNSstring.Split(',')
        "Domain . . . . . ." = $Net.DNSDomain
    }
    $CompInfo = [ordered]@{
        "Manufacturer . . ." = $ComputerSystem.Manufacturer
        "Model. . . . . . ." = $ComputerSystem.Model
        "Service Tag. . . ." = $Bios.SerialNumber
        "OS. . . . .  . . ." = $OperatingSystem.Caption
        "OS Build . . . . ." = (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\" | Select-Object -expandproperty ReleaseId)
        "OS Version . . . ." = $OperatingSystem.Version
    }

    # Output Information
    New-Object -TypeName PSobject -Property $NetInfo
    New-Object -TypeName PSobject -Property $CompInfo
    Get-WMIObject -ComputerName $ComputerName -Class Win32_LogicalDisk |
        Where-Object {$_.DriveType -eq 3} |
        Select-Object @{Name="Disk Letter. . . .";Expression={($_.Name)}},
            @{Name="Disk Size (GB) . .";Expression={([Math]::Round($_.size/1gb))}},
            @{Name="Free Space (GB). .";Expression={([Math]::Round($_.freespace/1gb))}}
}

New-Item -Path alias:gcinf -Value Get-CompInf >$null 2>&1

无论DNS搜索顺序输出是什么,如下所示

代码语言:javascript
运行
复制
DNS Servers. . . . : {203.1.64.1, 134.148.24.3, 134.148.24.1, 157.85.116.16}

如果我分开走这条线

代码语言:javascript
运行
复制
Get-WmiObject -Class Win32_NetworkAdapterConfiguration -ComputerName . |
    Where-Object {$_.IPConnectionMetric -ne $null} |
    Select-Object -ExpandProperty DNSServerSearchOrder

我得到了以下输出。

代码语言:javascript
运行
复制
203.1.64.1
134.148.24.3
134.148.24.1
157.85.116.16

如何让我的函数显示出来?

代码语言:javascript
运行
复制
DNS Servers. . . . : 203.1.64.1
                     134.148.24.3
                     134.148.24.1
                     157.85.116.16
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53734039

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档