Matteo
Matteo

Reputation: 39

Having trouble removing a user from a department in Powershell script

I have a user that is in a department that I can pull the department with the following line

    $UserDepartment = Get-ADUser $UserName -Property Department | Select-Object Department
    Write-Host $UserDepartment

which returns: @{Department=SALES}

I need a way to take the user out of the department while not deleting the user and wasn't sure how to go about it

Upvotes: 0

Views: 246

Answers (2)

Santiago Squarzon
Santiago Squarzon

Reputation: 60455

If you want to clear a user's attribute you should use the -Clear parameter.

See the Parameters section for this cmdlet.

Set-ADUser $user -Clear Department

Upvotes: 1

Rajiv Xavier
Rajiv Xavier

Reputation: 53

You could do something like

Get-ADUser $UserName | Set-ADUser -Department “” 

If you wish to mearly clear the department property

You can check out the powershell documentation for it here

Upvotes: 0

Related Questions