查询AD以查找名称为TC的OU中的所有计算机 [英] Query AD to find all the Computer in an OU with TC in their Name

查看:359
本文介绍了查询AD以查找名称为TC的OU中的所有计算机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在AD中搜索给定OU中名称中带有'TC'的所有计算机,这是我到目前为止所拥有的,但是它返回了所有计算机,我需要它仅返回带有' TC".

I'm trying to search AD for all machines in a given OU that have 'TC' in their name, this is what I have so far, but its returning all machines, I need it to return just the machines with 'TC' in their name.

$root = ([adsi]'LDAP://OU=PCs,OU=Student Computers,DC=student,DC=belfastmet,DC=int','objectCategory=computer')
$searcher = new-object System.DirectoryServices.DirectorySearcher($root)
$searcher.filter = "(objectCategory=computer)"
$searcher.pageSize=1000
$searcher.propertiesToLoad.Add("name")
$computers = $searcher.findall()
$computers | foreach {$_.properties.name}

我不太确定从现在起应该做什么,我是Powershell新手.

Not really sure what I should be doing from this point, I am a Powershell Newbie.

推荐答案

您有两个选择.您可以获取所有计算机,然后使用Powershell cmdlet进行过滤,或者ldap过滤器反映您想要的内容(更好).试试这个:

You have two options. You can get all computers and then filter using Powershell cmdlets, or your ldap filter reflects what you want (better). Try this:

$searcher.filter = "(&(objectCategory=computer)(cn=TN*))"

使用ActiveDirectoryModule,您可以使用过滤器在特定OU中找到计算机,并使用SearchBase将搜索限制为所需的OU(假设在以下示例中为YourDomain.com \ YourOU):

With ActiveDirectoryModule, you could find machines in a specific OU using filter and limit the search to the OU (assuming YourDomain.com\YourOU in the example below) you want with SearchBase:

$adcomputers = Get-ADComputer -Filter {name -like "TC*"} -Searchbase "OU=YourOU,DC=YourDomain,DC=com" 

这篇关于查询AD以查找名称为TC的OU中的所有计算机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆