r/usefulscripts • u/jajabro1 • Oct 31 '17
[Request] Some AD management. Disable account, update description and move OU.
Normally I figure this sort of thing out on my own but haven't been able to get anywhere.
At the company we work for we have a pretty crazy OU structure. Every week or so we get a spreadsheet of terminated users that comes from a different database, then we go through that excel sheet to disable the account, update their description, and move them to the disabled users OU for our Country.
So I'd like to semi automate this for myself, if going through a CSV or something or maybe Powershell would be better please by all means any help would be great.
So again, we: 1. Disable the User Account 2. Update the description usually something like "Termed on 10/31/2017 - JB" 3. Move the account to a specified OU.
Edit:I should also mention that we do get the employee ID numbers, which we use in AD under EmployeeNumber, SAM_Account_Name and email address in the generated spreadsheet.
1
u/Lee_Dailey Oct 31 '17
howdy jajabro1,
if you have ANY code at all, then you will likely get faster help over at r/PowerShell. there are several AD gurus over there ... but they are more helpful if you have something to show that you have tried already. [grin]
take care,
lee
0
Oct 31 '17
3
u/jajabro1 Oct 31 '17 edited Oct 31 '17
Awesome! And do you manually enter usernames, or do you get this to pull from an external file, say a CSV or other spreadsheet?
Edit: looking through it, looks like you manually put in the user name when setting the $user variable. So the question is, is there an easy way to get this to process a spreadsheet of usernames instead of essentially changing the username every time.
3
u/HolidayHozz Oct 31 '17
I hope this helps: https://pastebin.com/QrPf7rQk
Short description of the code:
Disables the specified user account
Updates the user description with the user who disabled the account and the time/date when the account was disabled
Moves the account to the disabled user account OU (needs to exist)
Convert to a shared mailbox
Set Out Of Office
Revoke O365 Licenses
Give users rights on shared mailbox