none
Updating Manager in AD RRS feed

  • Question


  • I hope this is easy for the Powershell gurus. I ended up doing it manually. It was only 10 users, so... 

    I want to get all users, that have a specific person as their manager, and then update the manager on all those users 

    Makes sense?

      


    Monday, September 8, 2014 11:08 AM

Answers


  • I hope this is easy for the Powershell gurus. I ended up doing it manually. It was only 10 users, so... 

    I want to get all users, that have a specific person as their manager, and then update the manager on all those users 

    Makes sense?

      


    # get all users with specific manager:
    Get-AdUser -Filter "manager -eq $manager"

    Now you can just reset the manager.


    ¯\_(ツ)_/¯



    • Edited by jrv Monday, September 8, 2014 11:32 AM
    • Marked as answer by Thomas Bruun Funch Monday, September 8, 2014 11:54 AM
    Monday, September 8, 2014 11:25 AM
  • Here is a better example using the PowerShell "Filter" property.

    Get-AdUser -filter 'manager -eq "CN=Joe Smith,OU=Sales,DC=TESTNET,DC=local"'

    You need to use the DN of the manager and not the name.


    ¯\_(ツ)_/¯

    Monday, September 8, 2014 11:34 AM
  • $oldmanager = (Get-ADUser <adprincipal>).DistinguishedName
    $newmanager = (Get-ADUser <adprincipal>).DistinguishedName
    Get-ADUser -filter "manager -eq '$oldmanager'" -properties Manager | Set-ADUser -Manager $newmanager

    Tuesday, September 9, 2014 2:52 PM

All replies

  • Hi

    try this:

    $domain = "domain name"
    $dse = [adsi]"LDAP://$domain"
    $filter = '(&(objectCategory=person)(objectSid=*)(!samAccountType:1.2.840.113556.1.4.804:=3)(manager=*))'
    $searcher = New-Object DirectoryServices.DirectorySearcher ($dse, $filter)
    $manager = $null
    $searcher.findall() | 
    ForEach-Object {
    [adsi]$_.path
    } |
    Format-Table -AutoSize -Property name, manager


    Hope this helps. Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

    Monday, September 8, 2014 11:16 AM

  • I hope this is easy for the Powershell gurus. I ended up doing it manually. It was only 10 users, so... 

    I want to get all users, that have a specific person as their manager, and then update the manager on all those users 

    Makes sense?

      


    # get all users with specific manager:
    Get-AdUser -Filter "manager -eq $manager"

    Now you can just reset the manager.


    ¯\_(ツ)_/¯



    • Edited by jrv Monday, September 8, 2014 11:32 AM
    • Marked as answer by Thomas Bruun Funch Monday, September 8, 2014 11:54 AM
    Monday, September 8, 2014 11:25 AM
  • Thanks, i did see this script. I just thought is was very extensive. I would think, is should be as simple as

    Get-Aduser Where -manager = something | Set-ADUser -manager something

    As you can properly tell, i am very new to this Powershell thing.

    Or maybe get the manager, and then get all of that users direct reports?

    Monday, September 8, 2014 11:26 AM
  • # get all users with specific manager:
    Get-AdUser -LDAPFilter 'manager=jsmith'

    Now you can just reset the manager.


    ¯\_(ツ)_/¯


    Yes, exactly. Thank you.

    Can i list the query results before reset the manager?

    Monday, September 8, 2014 11:30 AM
  • Here is a better example using the PowerShell "Filter" property.

    Get-AdUser -filter 'manager -eq "CN=Joe Smith,OU=Sales,DC=TESTNET,DC=local"'

    You need to use the DN of the manager and not the name.


    ¯\_(ツ)_/¯

    Monday, September 8, 2014 11:34 AM
  • Hi

    try this:

    $domain = "domain name"
    $dse = [adsi]"LDAP://$domain"
    $filter = '(&(objectCategory=person)(objectSid=*)(!samAccountType:1.2.840.113556.1.4.804:=3)(manager=*))'
    $searcher = New-Object DirectoryServices.DirectorySearcher ($dse, $filter)
    $manager = $null
    $searcher.findall() | 
    ForEach-Object {
    [adsi]$_.path
    } |
    Format-Table -AutoSize -Property name, manager


    Hope this helps. Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

    There are two better methods to access AD with ADSI:

    $searcher=[adsisearcher]'(&(objectCategory=person)(objectSid=*)(!samAccountType:1.2.840.113556.1.4.804:=3)(manager=*))'
    $searcher.findall() | 
        ForEach-Object { $_.GetDirectoryEntry() } |
        Format-Table -AutoSize -Property name, manager
     

    The defaults take care of the remainder.

    The next one is much faster.

    $searcher=[adsisearcher]'(&(objectCategory=person)(objectSid=*)(!samAccountType:1.2.840.113556.1.4.804:=3)(manager=*))'
    $searcher.PropertiesToLoad.AddRange(@('name','manager'))
    $searcher.findall() |
        ForEach-Object{
             New-Object PsObject -Property @{ 
                        Name=$_.Properties['name'][0]
                        Manager=$_.Properties['manager'][0]
                        }
        }


    ¯\_(ツ)_/¯

    Monday, September 8, 2014 11:51 AM
  • I recommend learning something about AD.  If you admin you must understand.

    Here is the simplest answer ro your issue.  Use the learning materials her to figure it out.

    $manager=(Get-Aduser <managerid>).DistinguishedName
    Get-AdUser -filter "manager -eq '$manager'" -properties Manager|
      ft name,manager


    ¯\_(ツ)_/¯


    • Edited by jrv Monday, September 8, 2014 12:17 PM
    Monday, September 8, 2014 12:15 PM
  • I recommend learning something about AD.  If you admin you must understand.

    Here is the simplest answer ro your issue.  Use the learning materials her to figure it out.

    $manager=(Get-Aduser <managerid>).DistinguishedName
    Get-AdUser -filter * -properties Manager|
      Where-Object{
          $_.manager -eq $manager
      }|
      ft name,manager


    ¯\_(ツ)_/¯

    I know plenty about AD, i am just very new to Powershell and it's syntax. The first one you posted worked fine :)

    Thank you.

    Monday, September 8, 2014 12:18 PM
  • I recommend learning something about AD.  If you admin you must understand.

    Here is the simplest answer ro your issue.  Use the learning materials her to figure it out.

    $manager=(Get-Aduser <managerid>).DistinguishedName
    Get-AdUser -filter * -properties Manager|
      Where-Object{
          $_.manager -eq $manager
      }|
      ft name,manager


    ¯\_(ツ)_/¯

    I know plenty about AD, i am just very new to Powershell and it's syntax. The first one you posted worked fine :)

    Thank you.


    I know but you still don't know AD PowerShell and all admins must know this going forwards.  Also PowerShell is now an Admin employment requirement everywhere so take the time to learn it. It will save you a lot of headaches.

    ¯\_(ツ)_/¯

    Monday, September 8, 2014 12:21 PM
  • True. Thank you for taking the time, and for the tips :)

    I surely will read up on Powershell, i just try to learn while doing.

    Monday, September 8, 2014 12:23 PM
  • $oldmanager = (Get-ADUser <adprincipal>).DistinguishedName
    $newmanager = (Get-ADUser <adprincipal>).DistinguishedName
    Get-ADUser -filter "manager -eq '$oldmanager'" -properties Manager | Set-ADUser -Manager $newmanager

    Tuesday, September 9, 2014 2:52 PM
  • $oldmanager = (Get-ADUser <adprincipal>).DistinguishedName
    $newmanager = (Get-ADUser <adprincipal>).DistinguishedName
    Get-ADUser -filter "manager -eq '$oldmanager'" -properties Manager | Set-ADUser -Manager $newmanager

    That was absolutely perfect.. Thank you very much.
    Wednesday, September 10, 2014 8:07 AM