If (‘Interested’ -in ‘PowerShell’) {‘Are you Participating in the PowerShell.org Forums?’}

If you’re interested in PowerShell and you’re not participating in the forums at PowerShell.org, you’re missing out on an awesome opportunity to learn from others instead of having to re-invent the wheel each time you need to accomplish a task. If you’ve been using PowerShell for a while and you’re not participating in the forums, then you’re missing out on an opportunity to help others who are asking for your assistance.

Recently, a topic was posted in the forums about retrieving the fully qualified domain name and IP address information from a DNS server with PowerShell.

Here’s the solution I provided:

#Requires -Version 3.0
#Requires -Modules DNSClient
function Get-MrDNSInfo {

<#
.SYNOPSIS
    Returns the FQDN and IP Address information for one or more computers.

.DESCRIPTION
    Get-MrDNSInfo is a function that returns the Fully Quailified Domain Name,
    along with IPv4 and IPv6 information for one or more computers which is
    retrieved from a Microsoft based DNS server.

.PARAMETER ComputerName
    The computer(s) to retrieve FQDN and IP Address information for. The default is
    the local computer.

.PARAMETER DNSServer
    The Microsoft based DNS Server to retrieve the FQDN and IP Address information
    from. The default is a DNS Server named DC01.

.EXAMPLE
    Get-MrDNSInfo -ComputerName pc01, pc02, server01

.EXAMPLE
     Get-MrDNSInfo -ComputerName pc01, pc02, server01 -DNSServer MyDNSServer

.EXAMPLE
     'pc01', 'pc02', 'server01' | Get-MrDNSInfo

.EXAMPLE
    Get-Content -Path .\Computers.txt | Get-MrDNSInfo -DNSServer MyDNSServer

.INPUTS
    String

.OUTPUTS
    PSCustomObject

.NOTES
    Author:  Mike F Robbins
    Website: http://mikefrobbins.com
    Twitter: @mikefrobbins
#>

    [CmdletBinding()]
    param (

        [Parameter(ValueFromPipeline)]
        [ValidateNotNullOrEmpty()]
        [string[]]$ComputerName = $env:COMPUTERNAME,

        [ValidateNotNullOrEmpty()]
        [string]$DNSServer = 'dc01'

    )

    PROCESS {
        foreach ($Computer in $ComputerName) {
            $DNSInfo = Resolve-DnsName -Server $DNSServer -Name $Computer -ErrorAction SilentlyContinue

            [PSCustomObject]@{
                NetBIOSName = $Computer
                FQDN = $DNSInfo.Name | Get-Unique
                IP4Address = $DNSInfo.IP4Address
                IPV6Address = $DNSInfo.IP6Address
            }

        }
    }
}

052914-1.jpg

Where else could you receive this type of information for free? A nicely formatted, well documented, and easy to read and follow solution.

µ