Solved

Change manager in Powershell

Posted on 2013-06-04
4
338 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 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

Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
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 from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

717 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