Solved

Change manager in Powershell

Posted on 2013-06-04
4
306 Views
Last Modified: 2013-07-03
Hey

I have a manager "Alex Alexsen"... I would like to change all users who have "Alex Alexsen" as manager to "Viggo Viggosen" using powershell

Thanks in advance

Mike
0
Comment
Question by:mikeydk
4 Comments
 

Author Comment

by:mikeydk
ID: 39218458
Viggo Viggosen as manager :)
0
 
LVL 10

Assisted Solution

by:Prashant Girennavar
Prashant Girennavar earned 166 total points
ID: 39218707
Try below code,

import-module activedirectory
get-aduser -filter * -searchbase "dc=contoso,dc=com" | select-object -Property samaccountname | %{set-aduser $_.samaccountname -Manager <NewManagerName>}

Open in new window


Please modify DN (DC=contoso , DC=Com) , according to your need ,  {Please be careful to select the right DN}

<NewMangerName> -->Your New manager Samaccount Name goes here.

Hope this help

Thanks,

-Prashant Girennavar.
0
 
LVL 7

Assisted Solution

by:BT15
BT15 earned 167 total points
ID: 39219637
pretending that the Windows ID for Alex Alexsen is alexa and the ID for Viggo Viggosen is viggov:

import-module activedirectory
get-aduser -Properties manager -filter {manager -eq "alexa"} | % {set-aduser $_.samaccountname -manager (get-aduser viggov).distinguishedname}

Open in new window

0
 
LVL 40

Accepted Solution

by:
Subsun earned 167 total points
ID: 39219659
Try this..

Replace AlexAlexsen wiwth samaccountname of Alex Alexsen
Replace ViggoViggosen wiwth samaccountname of Viggo Viggosen

I have added parameter -WhatIf for testing, you can remove it for applying changes..

 $Manager = (Get-ADUser "AlexAlexsen").DistinguishedName
 Get-ADUser -Filter *  -properties manager | ? {$_.manager -eq $Manager} | Set-ADUser -Manager "ViggoViggosen" -WhatIf

Open in new window

0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

"Migrate" an SMTP relay receive connector to a new server using info from an old server.
Disabling the Directory Sync Service Account in Office 365 will stop directory synchronization from working.
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now