none
Powershell Copy User Description from one Domain to another in one Forest RRS feed

  • Question

  • Hi.

    I would like to copy the Description field from one domain to another domain in the same forest.

    First I would like to get the following data from source domain

    - SamAccountName

    - Description

    - Office

    - Job Title

    - Department

    - Manager

    I would like to get these informations to a txt-file. That I can manage myself, I think.

    These values shoud then be set on the destination domain - and here my powershell skills are not suffecient. How do I add these values from txt-file to existing users? (if some users aren't there, the script should continue)....

    I can Get-AdUser -Identity xxx -Server sourcedomain and Get-AdUser -Identity xxx -Server destinationdomain from the same powershell windows.

    Regards

    Carsten


    Carsten

    • Moved by Bill_Stewart Thursday, June 26, 2014 8:55 PM Unanswerable drive-by question
    Tuesday, January 21, 2014 3:06 PM

All replies

  • Hi Carsten,

    you may also want to consider using Csv instead of txt (Export-Csv & Import-Csv) for storing object information. It saves quite a bit of time.

    Cheers,
    Fred


    There's no place like 127.0.0.1

    Tuesday, January 21, 2014 3:23 PM
  • you may also want to consider using Csv instead of txt (Export-Csv & Import-Csv) for storing object information. It saves quite a bit of time.

    Excellent point, I should have mentioned that.

    Don't retire TechNet! - (Don't give up yet - 12,575+ strong and growing)

    Tuesday, January 21, 2014 3:29 PM
  • Why use a CSV?

    Get-AdUser -Identity xxx -Server sourcedomain |
        ForEach-Object{
             Set-AdUser  -Identity $_.SAmAccountName -description $_.Description -Server destinationdomain
        }
    

    Just add the rest of the properties you want to copy.


    ¯\_(ツ)_/¯

    Tuesday, January 21, 2014 4:22 PM
  • Why use a CSV?

    Cuz they're fun.

    On a serious note, my assumption is that there is a point to having the output file generated other than just using it for input (historical records, taking up disk space, etc, etc).


    Don't retire TechNet! - (Don't give up yet - 12,575+ strong and growing)

    Tuesday, January 21, 2014 4:24 PM
  • Why use a CSV?

    Cuz they're fun.

    On a serious note, my assumption is that there is a point to having the output file generated other than just using it for input (historical records, taking up disk space, etc, etc).


    Don't retire TechNet! - (Don't give up yet - 12,575+ strong and growing)

    Whatever floats you commas.

    ¯\_(ツ)_/¯

    Tuesday, January 21, 2014 5:47 PM
  • Hi. Thank you very much for helping me out. I tried the above script and added in additional properties.

    When I run the script, I only get one line in my csv-file, the Office-field is empty and all items appear on screen instead of output to file.

    The script looks as follows:

    $ou = [adsi] "LDAP:<Server>"
    $searcher = New-Object System.DirectoryServices.DirectorySearcher $ou
    $searcher.Filter = 'objectClass=user'
    $result = $searcher.FindAll()
    foreach($contacts in $result)
    {
     $contact = $contacts.GetDirectoryEntry()
     $contact | Select-Object -Property @{Name="SamAccountName";Expression={$_.SamAccountName}},
               @{Name="Description";Expression={$_.Description}},
               @{Name="Office";Expression={$_.Office}},
               @{Name="Title";Expression={$_.Title}},
               @{Name="Department";Expression={$_.Department}},
               @{Name="Manager";Expression={$_.Manager}}
               }
    $contacts | Export-Csv -Path output.csv


    Carsten

    Wednesday, January 22, 2014 9:51 AM
  • That script has nothing to do with what you asked and is not any of the scripts that we posted.  Please read the responses carefully.


    ¯\_(ツ)_/¯

    Wednesday, January 22, 2014 10:08 AM
  • This is how you would extract users from AD into a CSV.

    $searcher=[adsisearcher]'(&(objectClass=user)(objectCategory=person))'
    $searcher.FindAll() |
        ForEach-Object{
            $_.GetDirectoryEntry() |
                Select-Object SamAccountName,Description,Office,Title,Department,Manager
        } |
        Export-Csv output.csv
    

    This is the base template.  All variations start like this when using ADSI.  Simple adjustments can be made to adapt to nearly all conditions.

    This has nothing to do with updating as asked in your question.


    ¯\_(ツ)_/¯

    Wednesday, January 22, 2014 10:20 AM