Powershell Command to export information in Active Directory User Properties

Mike Petonak 1 Reputation point
2022-11-10T18:43:16.87+00:00

We have a system that imports the users manager into an attribute called ExtentionAttribute2 field in the users properties field. What we are looking to do is locate a command that can be ran in powershell that will take the data found in the above field and place it into the manager field under organization tab. I was wondering if you can provide a command that will allow us to run it on an entire object in active directory which contains several sites at our business.

Thank you,
Mike

Active Directory
Active Directory
A set of directory-based technologies included in Windows Server.
6,182 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,449 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Rich Matheisen 45,671 Reputation points
    2022-11-10T19:35:46.74+00:00

    It might be as simple as this:

    Get-MailUser -ResultSize Unlimited |  
        if ($_.ExtensionAttribute2){  
            $mgr = $_.ExtensionAttribute2  
            $_ | Set-User -Manager $mgr  
        }  
    

    You don't say how the manager is represented in ExtensionAttribute2, though. If the value isn't acceptable for use in the Set-User cmdlet you might have to locate the manger's user (or contact) object in the AD and use, say, its distinguishedName instead of the value found in ExtensionAttribute2.


  2. Mike Petonak 1 Reputation point
    2022-11-10T19:52:11.707+00:00

    Wouldnt it be Get-ADuser since the changes would be made from Active Director User accounts?


  3. Flávio Cavalcanti 1 Reputation point
    2022-11-10T20:20:54.507+00:00

    You can use something like this for get the propertie value and save in a enviroment variable:

    $temp_ea2value=Get-ADUser -Identity [User Name Pattern] -Properties ExtensionAttribute2 | Select-Object -ExpandProperty ExtensionAttribute2  
    

    And then set it using :

    Set-ADUser -Identity [User Name Pattern] -Department $temp_ea2value  
    
    0 comments No comments