首页 > 解决方案 > 如何在没有 DnsServer 模块的情况下使用 PowerShell 检索所有 DNS 记录?

问题描述

我使用的是 Windows Server 2008 R2。我发现的每篇文章都建议对 Powershell 使用 DnsServer 模块,但这些机器不支持它。那么我还能如何获得这些记录呢?我正在尝试将它们导出到 CSV 文件。“nslookup”并没有真正做到这一点。

标签: powershelldnswindows-7

解决方案


至于...

我使用的是 Windows Server 2008 R2。我发现的每篇文章都建议对 Powershell 使用 DnsServer 模块,但这些机器不支持它。

...那,不是一个有效的陈述。它们在 Win7 和 W2K8 上受支持。哎呀,您可以在 Vista 上使用它们 - 正如 Microsoft 所记录的那样。

适用于 Windows Vista Service Pack 1 的 Windows Server 2008 远程服务器管理工​​具的描述

系统要求

RSAT 可以安装在以下配置的 32 位和 64 位版本上: 带有 SP1 的 Windows Vista Ultimate 或更高版本的 Windows Vista Service Pack

  • 带有 SP1 的 Windows Vista Enterprise 或更高版本的 Windows Vista Service Pack
  • 带有 SP1 或更高版本的 Windows Vista Service Pack 的 Windows Vista Business
  • RSAT 可用于管理 32 位和 64 位版本的 Windows Server 2008。

RSAT 不应安装在运行 Windows Server 2003 管理工具包或 Windows 2000 Server 管理工具包的计算机上。请在安装 RSAT 之前从计算机中删除所有管理工具包版本。

一次只能在计算机上安装一份 RSAT 副本。在安装新软件包之前,请删除所有现有的 RSAT 版本。这包括使用不同语言的任何副本。

您需要在 Win7 主机上安装 RAT 工具,您必须在 W2K8/R2 上启用它们。

带有 Service Pack 1 (SP1) 的 Windows 7 远程服务器管理工​​具

实际上,如果这是不允许的。您不需要安装 RSAT 工具,您可以将它们从任何运行 RSAT 的 DC 或服务器代理到您的工作站。这是一种非常常见的做法,它被称为隐式远程处理,并且在网络上的大量资源中都有详细记录。否则,您需要使用 ADSI、.Net 库...

Dns.GetHostEntry 方法

Dns.GetHostByAddress 方法

# 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) 

... 或其他 3rdP 工具。然而,如果你使用这个 3rdP 路由,你也可以在你的一台机器上安装官方的 RSAT。

使用“使用 PowerShell Active Directory Cmdlet 而不安装”或“windows 7 获取 dns 记录”进行快速搜索将为您提供包含示例的列表。

在不安装任何软件的情况下使用 PowerShell Active Directory Cmdlet

在不加载 RSAT 的情况下使用 AD 模块

因此,您可以使用以下示例从远程 Windows Server 2008 R2(安装了 RSAT for AD 的 DC 或成员服务器或工作站)导入 Active Directory cmdlet:

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

另一种方法是将远程 PowerShell 会话导出到本地模块:

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

使用加载模块

Import-Module ActiveDirectory

推荐阅读