[英]Powershell How to Get list of computers from two different OU's in the same script
I know how to get a list of computers in specific OU's using powershell, and I can use a like command to;我知道如何使用 powershell 获取特定 OU 中的计算机列表,并且我可以使用类似命令; however I am looking .但是我正在寻找。 How can I get a list of computers in two different OU's that start Like COMP using Powershell ?如何使用 Powershell 获取以 Like COMP 开头的两个不同 OU 中的计算机列表?
You could loop over the list of OUs and repeat the same query multiple times:您可以遍历 OU 列表并多次重复相同的查询:
# fetch the target OUs
$OUs = Get-ADOrganizationalUnit -Filter "Name -like 'Comp*'"
# call Get-ADComputer once for each OU
$Computers = $OUs |ForEach-Object {
Get-ADComputer -Filter * -SearchBase $_.distinguishedName
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.