Asked by:
Disable Account Powershell

-
Hello guys.
I have a question, i want to make a script that disable an user and moves the OU, but i need it to prompt the question "what user you want to disable" and read it.
That i can do, but i need that to be the "postalCode" parameter.
So would be something like this
$cod = Read-Host "Type user code"
Disable-ADACcount where postalCode = $cod
Move-ADObject OU=ZENSA.........
Any idead how i can do this ?
I need to do by postalCode or any other different field, because i need to put my company code on that....
Question
All replies
-
-
-
I would suggest using either the employeeID or employeeNumber attributes, just to avoid confusion.
Edit: The Disable-ADAccount cmdlet does not support a filter (or a Where). You need to retrieve either sAMAccountName or distinguishedName, using Get-ADUser. For example (not tested):
$ID = Read-Host "Enter postalCode" $NTName = (Get-ADUser -Filter {postalCode -eq $ID}).sAMAccountName If ($NTName.Count -eq 1) { Disable-ADAccount -Identity $NTName } Else {"More than one user, or no user found"}
I check that one and only one user is found, to avoid problems.
Richard Mueller - MVP Enterprise Mobility (Identity and Access)
- Edited by Richard MuellerMVP Friday, March 24, 2017 6:36 PM
- Proposed as answer by Mahdi TehraniModerator Monday, March 27, 2017 6:50 PM
-
-
Hi,
Thank you for the feedback, if it works for you, we would appreciate you to mark them as answers, it will be greatly helpful to others who have the same question.
Best regards,
WendyPlease remember to mark the replies as answers if they help.
If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.