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

Windows for business Windows Client for IT Pros Directory services Active Directory
Windows for business Windows Server User experience PowerShell
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Rich Matheisen 47,901 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

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.