Solved

Remove Manager Attribute via PS

Posted on 2014-10-31
8
412 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
LVL 39

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 39

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 39

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

832 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