Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Change manager in Powershell

Posted on 2013-06-04
4
Medium Priority
?
364 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
 
LVL 1

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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

Had a business requirement to store the mobile number in an environmental variable. This is just a quick article on how this was done.
Microsoft Office 365 is a subscriptions based service which includes services like Exchange Online and Skype for business Online. These services integrate with Microsoft's online version of Active Directory called Azure Active Directory.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…
Suggested Courses

636 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