Synchronizing User AD details to Contacts across Multiple Untrusted Domains RRS feed

  • Question

  • Greetings

    Welcome to the complexity of governmental departments.

    My goal/requirement is to take User AD details from a domains and create AD Objects (contacts) for exchange to use.

    We are doing this at a AD level and not using Exchange as this is been done over several domains all untrused. 

    The script I have complete so far does the job, with one hiccup.

    Each Domain has different ways of setting up users and what attributes are used, thus ever so often it hits a NULL entry.

    And then -OtherAttributes fails cause I'm now piping in nothing.

    So any suggestion would be welcome.

    I have tried writing each attribute we required for each domain but this turned into a MESS and complicate to troubleshoot.

    I have tried to find a way to do an IF THEN ELSE for the Hashtable but, probably doing it wrong :P

    # Loads ActiveDirectory Powershell Commands is not loaded #
    if(@(get-module | where-object {$_.Name -eq "ActiveDirectory"} ).count -eq 0) {import-module ActiveDirectory}
    # AD_OU location to be SCANNED for users
    $OU_Contact = "OU=Contact,OU=Temp,DC=DomainA,DC=gov,DC=uk"
    $OU_Users = "OU=USER,DC=Domain2,DC=gov,DC=uk"
    ## The following filter is used by Get-ADObject to decide which users will have contacts created.
    $strSelectUsers = { ObjectClass -eq "user" -and msExchHomeServerName -like "*" -and -not msExchHideFromAddressLists -eq $true }
    $DOMAIN_1 = ""
    $DOMAIN_2 = ""
    $objTargetDC = Get-ADDomainController -Discover -DomainName $DOMAIN_1
    $objSourceDC = Get-ADDomainController -Discover -DomainName $DOMAIN_2
    $sourceDC = [string]$objSourceDC.HostName
    $targetDC = [string]$objTargetDC.HostName
    #Gets user in OU writes contacts to OU using Porperties# ERROR not importing last and first names.
    # Null DATA corrction lines {If ($_.HomePhone -eq "") {$HPhone = $Null} Else {$HPhone = $_.HomePhone}
    Get-ADObject -Filter $strSelectUsers -Server $sourceDC -SearchBase $OU_Users -SearchScope OneLevel -Properties * |
    ForEach-Object {New-ADObject -Type contact -Name $_.displayName `
    -OtherAttributes @{'displayname'=$_.displayName;'mail'=$_.mail;'proxyAddresses'=$_.proxyAddresses;'givenName'=$_.givenName;'sn'=$;} `
    -Path $OU_Contact}


    • Moved by Bill_Stewart Friday, October 31, 2014 5:15 PM This is not "fix script for me" forum
    Monday, July 28, 2014 2:47 PM

All replies

  • Try using Get-AdUser instead of object.

    You cannot pipe a null so you are getting non-user objects or have users with those items not set.


    Wednesday, September 3, 2014 4:24 PM