[英]Get computer list from OU using Get-ADComputer cmdlet
I´m struggling with getting a list of computers from a specific OU via the Get-ADComputer
cmdlet. 我正在努力通过Get-ADComputer
cmdlet从特定的OU Get-ADComputer
计算机列表。 The OU contains only computers. OU仅包含计算机。 I specify the OU where the computers are placed and then I try to filter the objects based on hostname. 我指定放置计算机的OU,然后尝试根据主机名过滤对象。
I want to list all computers whose hostname begins with "PC100". 我想列出所有主机名以“ PC100”开头的计算机。 No matter what comes after the second zero. 无论第二个零之后是什么。
The code: 编码:
Get-ADComputer -SearchBase "OU=PC,OU=LAB,DC=test,DC=cz" -Filter * | Select-Object name | where -Property Name -Match "PC100*"
I went through plenty of articles but haven't figured it out yet. 我浏览了很多文章,但还没有弄清楚。 PowerShell doesn't return any error, it simply doesn't generate any output. PowerShell不会返回任何错误,它只会生成任何输出。
Try this one 试试这个
Get-ADComputer -SearchBase "OU=PC,OU=LAB,DC=test,DC=cz" -Filter {Name -eq "PC100"} -Properties Name | Select-Object Name
This assumes that PC
organizational unit is nested under LAB
, and that the name of the computer is exactly PC100
. 这假定PC
组织单位嵌套在LAB
下,并且计算机的名称恰好是PC100
。 If you don't know the exact name and you know that it PC100
is part of the name, change it to -Filter {Name -like "*PC100*"}
如果您不知道确切的名称,并且知道PC100
是名称的一部分,请将其更改为-Filter {Name -like "*PC100*"}
And don't pull all properties when you don't need them, it can cause potential performance issues 并且在不需要它们时不要拉所有属性,这可能会导致潜在的性能问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.