代码示例: 通过使用PowerShell可以在ADUC中创建和管理Saved Queries,以下是一些示例命令:
New-Object -ComObject "ADSystemInfo" | Select-Object -ExpandProperty DefaultNamingContext $searcher = [adsisearcher]"(objectCategory=User)" $searcher.PropertiesToLoad.Add("givenName") $searcher.PropertiesToLoad.Add("sn") $searcher.PropertiesToLoad.Add("mail") $query = $searcher.FindAll() $ldapQuery = '(' foreach($result in $query) { $userDN = $($result.Properties.Item("distinguishedName")) $ldapQuery += "(distinguishedName=$userDN))" } $ldapQuery # Paste this in the Saved Query ObjectDN property field.
$oldQuery = [adsi]"LDAP://cn=My Saved Query,CN=Saved Queries,CN=Configuration,DC=domain,DC=com" $newQuery = $oldQuery.Copy() $newQuery.SetInfo() $newQuery.Properties["description"].Value = "A query description" $newQuery.Properties["msSavedQueryFilter"].Value = "(objectCategory=computer)" $newQuery.CommitChanges()