
Ok, I think I see a few things that might need to change. Let's try
referring to the groups and computers by DN rather than by name so that they
can be found from domains other than the one in which they reside, and let's
use the parent domain connection which should be able to resolve DNs to the
children domains just fine.
Here's that script:
$defaultConnection = Connect-QADService
$groups = @{}
$groupNames = @(
'cn=MS02,dc=us,dc=test2ad,dc=super,dc=com',
'cn=MS03,dc=us,dc=test2ad,dc=super,dc=com',
'cn=MS04,dc=us,dc=test2ad,dc=super,dc=com'
)
$domainConnections =@(
(Connect-QADService -Service 'test2ad.super.com'),
(Connect-QADService -Service 'us.test2ad.super.com'),
(Connect-QADService -Service 'invest.test2ad.super.com')
)
$rootDomainConnection = $domainConnections[0]
foreach ($groupName in $groupNames) {
$groups[$groupName] = @((Get-QADGroup $groupName -Connection
$rootDomainConnection).members)
}
$domainConnections | ForEach-Object {
Get-QADComputer -OSName 'Windows*Server*' -SizeLimit 0 -Connection $_ |
ForEach-Object {
## Pick the first group as the default smallest group
$smallestGroup = $groupNames[0]
foreach ($groupName in $groupNames) {
## If any group contains our server dn, get the next server dn
if ($groups[$groupName] -contains $_.dn) {
return
}
## Update the smallest group if the current one is smaller
if ($groups[$groupName].count -lt $groups[$smallestGroup].count)
{
$smallestGroup = $groupName
}
}
## Add the server and update the appropriate members hash table
Add-QADGroupMember -Identity $smallestGroup -Member
$_.dn -Connection $rootDomainConnection
$groups[$smallestGroup] += $_.dn
}
}
Does this get us any closer? Sure we can always go the route of having
groups in each domain but I don't think that should be necessary. It seems
we're just having an issue with the recognition of the group and the
computer using the same connection, so I wanted to try using DNs to identify
each object and using the root connection to manage the objects correctly.
Please let me know how this works out for you.
--
Kirk Munro [MVP]
Poshoholic
http://poshoholic.com
groupe de discussion : A0C30C4F-31F4-4E4E-AAD3-45A09E0F372B@microsoft.com...