Link to home
Start Free TrialLog in
Avatar of ipsec600
ipsec600

asked on

Remove Manager Attribute via PS

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.
Avatar of Rajitha Chimmani
Rajitha Chimmani
Flag of United States of America image

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
Avatar of ipsec600
ipsec600

ASKER

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.
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"
ASKER CERTIFIED SOLUTION
Avatar of footech
footech
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
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.
My example does provide a filter, "*", which is valid and works.
Get-ADUser requires one of the following parameters: -Identity, -Filter, or -LdapFilter
Excellent!! The PS command works perfectly that I was expecting, Thank you footech. And also thanks to Rajitha!!