13

Just wrote a script that disables an account, moves it to a disabled OU and changes the description on the user object, but I want to make it more efficient.

My work AD structure has all users under Root - accounts OU, and the 50 or so department OUs under that accounts OU.

How can I START my search at the accounts OU and have it check every sub OU in accounts?

4

1 回答 1

29

如果我理解正确,您需要使用 -SearchBase:

Get-ADUser -SearchBase "OU=Accounts,OU=RootOU,DC=ChildDomain,DC=RootDomain,DC=com" -Filter *

请注意,Get-ADUser 默认使用

 -SearchScope Subtree

所以你不需要指定它。正是这一点为您提供了所有子 OU(和子子 OU 等)。

于 2013-05-05T07:27:05.713 回答