?
Solved

Change manager in Powershell

Posted on 2013-06-04
4
Medium Priority
?
357 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 

Author Comment

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

Assisted Solution

by:Prashant Girennavar
Prashant Girennavar earned 664 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 668 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 668 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
Uncontrolled local administrators groups within any organization pose a huge security risk. Because these groups are locally managed it becomes difficult to audit and maintain them.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

752 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