Skip to content

Move Computer to OU in a multidomain environment

Featured Replies

Hi Gurus,

I have been using Onevinn's TSCommander by the brilliant Johann, but it fails in an environment where I have a forest with 2 subdomains. Got ~90 DCs, trust is full,  but since the ConfigMgr site server is in Domain A, when I image computers in Domain B, the MoveToOU server-side script won't find a distinguished name - I think the built-in underlying scripts were never meant to work in such a scenario. Onevinn's Event log says, trying to find DN for the computer... but fails, so no OU move, nor addToADGroup, nothing works...

Trying to run a custom script, but I have no other ideas than running (get-adforest).domains | % {get-adcomputer <computer> -server $_} to grab the device... probably it's something trivial though... 

I contacted Johan and here's his reply

Hmm, I have actually done this once.... He will have to run a ds-Query against Global Catalog, as opposed to Ldap..... Or pay me to give him a custom TSCommander, including him signing a paper that he's responsible for not having several computers with the same samAccountName in multiple Domains ;)

 

  • Author

Haha, nice! :) Well site codes are used so computer names are 100% unique due to the conventions in place.

 

$tsenv = New-Object -COMObject Microsoft.SMS.TSEnvironment
$OU = $tsenv.Value('OSDDomainOUName')

$targetdomain = $tsenv.Value('OSDDomainName')
$imaged_device = $tsenv.Value('OSDcomputerName')
$ErrorActionPreference = 'SilentlyContinue'

function getcmp($computer){
    $CompResultList = @()
    $DomainList = @("domainA","domainB")
     foreach($Domain in $DomainList)
      {
        if (!(get-adcomputer -identity $computer -Server $Domain -ErrorAction SilentlyContinue))
        {continue}
        $CompResultList += get-adcomputer -identity $imaged_device -Server $Domain
    }
    
    return $CompResultList
 }  
get-adcomputer $(getcmp -computer $imaged_device).name -server $targetdomain |  Move-ADObject -TargetPath $OU -server $targetdomain

is import module for AD missing?

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.