简体   繁体   English

Powershell 如何在同一脚本中从两个不同的 OU 获取计算机列表

[英]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.

相关问题 将计算机列表导入 Powershell 以获取 OU - Importing a list of computers to Powershell to get OU 从活动目录中的某些OU获取计算机列表? - Get computers list from certain OU in active directory? 用于从计算机列表中获取外部 IP 地址的 Powershell 脚本 - Powershell Script to get external IP address from a list of computers 如何使用WMI获取计算机的当前OU并列出该OU中的所有其他计算机? - How do I use WMI to get the current OU of a computer and list all other computers in that OU? 用于从 OU 列表创建新组的 Powershell 脚本,然后将用户对象从 OU 添加到组 - Powershell Script to create a new Group from a list of OU and then add User Objects from the OU to the group Powershell:查找AD中的所有计算机,但排除某些OU - Powershell: Find all computers in AD but exclude certain OU's 如何使用Powershell从Active Directory中的特定OU获取没有ManageBy的组列表 - How to get list of groups with no ManageBy from a specific OU in Active Directory with Powershell 通过powershell获取Active Directory中不同OU中的所有用户 - Get all users in ActiveDirectory in different OU by powershell Powershell:如何从 OU 中的用户获取特定属性 - Powershell: How to get specific properties from users in a OU PowerShell脚本可排除在AD中被禁用的计算机列表 - PowerShell script to exclude a list of computers from getting disabled in AD
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM