Solved

Remove Manager Attribute via PS

Posted on 2014-10-31
8
455 Views
Last Modified: 2014-11-02
Hi experts,

I am trying to remove/delete manager information from the moved users OU, and the PS script is working for single user as below but while i am trying to search for moved OU in the domain, and try to remove manager information for all users those belong to that OU returning with error, could you please advise.

Working script

Set-ADUser ittest -manager $null

The below script is not working:

$Server = "dc01.test.com"
$SearchBase = "OU=Moved Users,DC=test,DC=com"
Get-ADUser -Identity * -Server $Server -SearchBase $SearchBase -Properties * |
Select-Object -Property | Set-ADUser -manager $null

ERROR:

Get-ADUser : Parameter set cannot be resolved using the specified named paramet
ers.
At line:1 char:11
+ Get-ADUser <<<<  -Identity * -Server $Server -SearchBase $SearchBase -Propert
ies * |
    + CategoryInfo          : InvalidArgument: (:) [Get-ADUser], ParameterBind
   ingException
    + FullyQualifiedErrorId : AmbiguousParameterSet,Microsoft.ActiveDirectory.
   Management.Commands.GetADUser
Could you please advise.
0
Comment
Question by:ipsec600
  • 3
  • 3
  • 2
8 Comments
 
LVL 16

Expert Comment

by:Rajitha Chimmani
ID: 40416317
Identity * will not work to get all users. You have to provide a filter to list all objects. Try this. I have not tested it though.

Get-ADUser -Server $Server -SearchBase $SearchBase -Properties * -Filter {ObjectType -eq "User"} | Set-ADUser -manager $null
0
 

Author Comment

by:ipsec600
ID: 40416375
Hi Rajitha,

Thank you for your reply, now the PS command become successful without returning any error but it is not removing Manager information for users, could you please advise.
0
 
LVL 16

Expert Comment

by:Rajitha Chimmani
ID: 40416383
Try this. I would recommend trying $null in double quotes for single user first.

Get-ADUser -Server $Server -SearchBase $SearchBase -Properties * -Filter {ObjectType -eq "User"} | Set-ADUser -manager "$null"
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 40

Accepted Solution

by:
footech earned 500 total points
ID: 40416387
You can use the following.  There is no need to return all the properties as you aren't doing anything with them, and it will just slow the query down.
Get-ADUser -Filter * -Server $Server -SearchBase $SearchBase | Set-ADUser -Clear Manager
#this also works
Get-ADUser -Filter * -Server $Server -SearchBase $SearchBase | Set-ADUser -Manager $null

Open in new window

0
 
LVL 40

Expert Comment

by:footech
ID: 40416392
BTW, Rajitha's doesn't work because the filter is incorrect.  It should be {ObjectClass -eq "User"} but that's also unnecessary since all objects that Get-ADUser returns have an ObjectClass of User.
0
 
LVL 16

Expert Comment

by:Rajitha Chimmani
ID: 40416440
I agree that the filter is incorrect but -Filter is a required parameter for Get-ADUser. You might not be able to run it without providing some filter.
0
 
LVL 40

Expert Comment

by:footech
ID: 40416466
My example does provide a filter, "*", which is valid and works.
Get-ADUser requires one of the following parameters: -Identity, -Filter, or -LdapFilter
0
 

Author Closing Comment

by:ipsec600
ID: 40418753
Excellent!! The PS command works perfectly that I was expecting, Thank you footech. And also thanks to Rajitha!!
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

This article will help you understand what HashTables are and how to use them in PowerShell.
A brief introduction to what I consider to be the best editor for PowerShell.
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 Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

839 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