导出 AD 中多个 OU 中所有计算机的简单列表

Moo*_*cus 3 windows powershell active-directory

我有一个程序,可以根据文本文档选择要连接的计算机。该列表只需要包含计算机名称,每行 1。没有其他的。

我需要一个我可以运行的命令或脚本来产生这个。我想每周自动运行一次此脚本以使用新计算机更新列表。服务器正在运行 Windows Server 2008 R2。我已经安装了 Quest AD 模块,但我没有找到太多使用它的帮助。

任何帮助,将不胜感激!谢谢 :)

Pim*_* IT 7

POWERSHELL 获取广告计算机对象列表输出到文件

查看下面的这些PowerShell单行示例,您可以更改和测试它的过滤器部分,以满足您对从 ADOperating System等属性查询的内容的需求。

请务必更改输出文本文件的名称和位置,您需要将其输出到Out-File C:\Test\Test.txt零件文件位置。

用于非服务器列表

Get-ADComputer -Filter {OperatingSystem -NotLike "*Server*"} | Select -Expand Name | Out-File C:\Test\Test.txt
Run Code Online (Sandbox Code Playgroud)

用于服务器列表

Get-ADComputer -Filter {OperatingSystem -Like "*Server*"} | Select -Expand Name | Out-File C:\Test\TestServers.txt
Run Code Online (Sandbox Code Playgroud)

用于自定义描述列表

(您可以从AD Users and Computers特定 OU 中选择所有 AD 计算机对象,然后right-click选择PropertiesALL COMPUTER OBJECTS 时选择,然后为值添加与 OU 相关的自定义和唯一字符串Description(请参见下面的屏幕截图)。然后您可以细化下面的搜索过滤器以查找对Description每个 OU具有此自定义唯一值的 AD 计算机)

Get-ADComputer -Filter {Description -Like "*CustomTestString*"} | Select -Expand Name | Out-File C:\Test\Custom.txt
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明


Con*_*989 7

我认为这是对的,从我没有要测试的域的计算机上进行了一些更改。

# a PowerShell script, licensed under GPL ;)
#
# importing dependancy, assuming it's already installed.
# Install RSAT for Windows workstation, AD DS role for Windows Server if missing
Import-Module "ActiveDirectory"

# an array containing the OU paths we'll enumerate
$OUpaths = @("OU=Allocated,OU=Workstations,OU=WDS Org,DC=wds,DC=wdsgroup,DC=local","OU=Available,OU=Workstations,OU=WDS Org,DC=wds,DC=wdsgroup,DC=local")

# loop though the array of OUs, adding the computers to a list ('Object' really)
foreach ($iOUpath in $OUpaths)
    {
        ($objComputers += Get-ADComputer -SearchBase $iOUpath -Filter *)    #You might need to refine the query witha 'Filter' depending on your AD structure
    }

# dump the list to a file
$objComputers | Select name | Export-Csv -LiteralPath "C:\Temp\ComputerNames.txt" -NoTypeInformationA
Run Code Online (Sandbox Code Playgroud)