Carlos
Carlos

Reputation: 13

How to retrieve all DNS records using PowerShell without DnsServer module?

I'm using a Windows Server 2008 R2. Every post I find suggests using DnsServer module for Powershell, but it is not supported for these machines. So how else can I get these records? I am trying to export them to a CSV file. "nslookup" doesn't really do the trick.

Upvotes: 1

Views: 6133

Answers (1)

postanote
postanote

Reputation: 16096

As for the...

I'm using a Windows Server 2008 R2. Every post I find suggests using DnsServer module for Powershell, but it is not supported for these machines.

... that, is not a valid statement. They are supported on Win7 and W2K8. Heck, you could use them on Vista - as documented per Microsoft.

Description of Windows Server 2008 Remote Server Administration Tools for Windows Vista Service Pack 1

System requirements

RSAT can be installed on 32-bit and 64-bit editions of the following configurations: Windows Vista Ultimate with SP1 or a later Windows Vista service pack

  • Windows Vista Enterprise with SP1 or a later Windows Vista service pack
  • Windows Vista Business with SP1 or a later Windows Vista service pack
  • RSAT can be used to manage 32-bit and 64-bit editions of Windows Server 2008.

RSAT should not be installed on a computer that is running the Windows Server 2003 Administration Tools Pack or the Windows 2000 Server Administration Tools Pack. Please remove all Administration Tools Pack versions from the computer before you install RSAT.

Only one copy of RSAT can be installed on a computer at one time. Before you install a new package, remove any existing versions of RSAT. This includes any copies that are in different languages.

You need to install the RAT tools on your Win7 host, you have to enable them on W2K8/R2.

Remote Server Administration Tools for Windows 7 with Service Pack 1 (SP1)

Actually, if that is not allowed. You don't need to install the RSAT tools, you can proxy them from any DC or server running RSAT to your workstation. This is a very common practice, it's called implicit remoting and well documented in plenty of resources all over the web. Otherwise, you need to use ADSI, the .Net libraries...

Dns.GetHostEntry Method

Dns.GetHostByAddress Method

# The following code returns the IPv4 address of a given alias or host: 
[System.Net.Dns]::GetHostAddresses('someDnsName').IPAddressToString

# The below code returns the HostName (CName) and aliases of an IP: 
[System.Net.Dns]::GetHostByAddress('172.12.34.56')

$name = 'someName'
$fqdn = [System.Net.Dns]::GetHostEntry($name).HostName 
$ip = [System.Net.Dns]::GetHostAddresses($fqdn).IPAddressToString
$result = [System.Net.Dns]::GetHostByAddress($ip) 

... or other 3rdP tools. Yet, if you use this 3rdP route, you may as well install the official RSAT on one of your machines.

A quick search using say, 'Use PowerShell Active Directory Cmdlets Without Installing', or 'windows 7 get dns records' will give you that list with samples.

Use PowerShell Active Directory Cmdlets Without Installing Any Software

Using AD module without loading RSAT

So, You can then use the following example to import the Active Directory cmdlets from a remote Windows Server 2008 R2 (either DC or member server or workstation with RSAT for AD installed):

$session = New-PSSession -computerName 'TargetMachineWithRsat'
Invoke-Command { Import-Module ActiveDirectory } -Session $session
Import-PSSession $session

An alternate way is to export the remote PowerShell session into a local module:

$session = New-PSSession -computerName 'TargetMachineWithRsat'
Invoke-Command { Import-Module ActiveDirectory } -Session $session
Export-PSSession -Session $session -CommandName *-AD* -Outputmodule ActiveDirectory -AllowClobber

Load the module using

Import-Module ActiveDirectory

Upvotes: 1

Related Questions