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:
1#Requires -Version 3.0
2#Requires -Modules DNSClient
3function Get-MrDNSInfo {
4
5<#
6.SYNOPSIS
7 Returns the FQDN and IP Address information for one or more computers.
8
9.DESCRIPTION
10 Get-MrDNSInfo is a function that returns the Fully Quailified Domain Name,
11 along with IPv4 and IPv6 information for one or more computers which is
12 retrieved from a Microsoft based DNS server.
13
14.PARAMETER ComputerName
15 The computer(s) to retrieve FQDN and IP Address information for. The default is
16 the local computer.
17
18.PARAMETER DNSServer
19 The Microsoft based DNS Server to retrieve the FQDN and IP Address information
20 from. The default is a DNS Server named DC01.
21
22.EXAMPLE
23 Get-MrDNSInfo -ComputerName pc01, pc02, server01
24
25.EXAMPLE
26 Get-MrDNSInfo -ComputerName pc01, pc02, server01 -DNSServer MyDNSServer
27
28.EXAMPLE
29 'pc01', 'pc02', 'server01' | Get-MrDNSInfo
30
31.EXAMPLE
32 Get-Content -Path .\Computers.txt | Get-MrDNSInfo -DNSServer MyDNSServer
33
34.INPUTS
35 String
36
37.OUTPUTS
38 PSCustomObject
39
40.NOTES
41 Author: Mike F Robbins
42 Website: http://mikefrobbins.com
43 Twitter: @mikefrobbins
44#>
45
46 [CmdletBinding()]
47 param (
48
49 [Parameter(ValueFromPipeline)]
50 [ValidateNotNullOrEmpty()]
51 [string[]]$ComputerName = $env:COMPUTERNAME,
52
53 [ValidateNotNullOrEmpty()]
54 [string]$DNSServer = 'dc01'
55
56 )
57
58 PROCESS {
59 foreach ($Computer in $ComputerName) {
60 $DNSInfo = Resolve-DnsName -Server $DNSServer -Name $Computer -ErrorAction SilentlyContinue
61
62 [PSCustomObject]@{
63 NetBIOSName = $Computer
64 FQDN = $DNSInfo.Name | Get-Unique
65 IP4Address = $DNSInfo.IP4Address
66 IPV6Address = $DNSInfo.IP6Address
67 }
68
69 }
70 }
71}
Where else could you receive this type of information for free? A nicely formatted, well documented, and easy to read and follow solution.
µ