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,Micr osoft.Acti veDirector y.
Management.Commands.GetADU ser
Could you please advise.
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,Micr
Management.Commands.GetADU
Could you please advise.
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.
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"
Get-ADUser -Server $Server -SearchBase $SearchBase -Properties * -Filter {ObjectType -eq "User"} | Set-ADUser -manager "$null"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
Get-ADUser requires one of the following parameters: -Identity, -Filter, or -LdapFilter
ASKER
Excellent!! The PS command works perfectly that I was expecting, Thank you footech. And also thanks to Rajitha!!
Get-ADUser -Server $Server -SearchBase $SearchBase -Properties * -Filter {ObjectType -eq "User"} | Set-ADUser -manager $null