Solved

Remove Manager Attribute via PS

Posted on 2014-10-31
8
562 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
[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
  • 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
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.

 
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

Learn by Doing. Anytime. Anywhere.

Do you like to learn by doing?
Our labs and exercises give you the chance to do just that: Learn by performing actions on real environments.

Hands-on, scenario-based labs give you experience on real environments provided by us so you don't have to worry about breaking anything.

Question has a verified solution.

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

A company’s centralized system that manages user data, security, and distributed resources is often a focus of criminal attention. Active Directory (AD) is no exception. In truth, it’s even more likely to be targeted due to the number of companies …
Always backup Domain, SYSVOL etc.using processes according to Microsoft Best Practices. This is meant as a disaster recovery process for small environments that did not implement backup processes and did not run a secondary domain controller that ne…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

689 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