Using powershell to manage user accounts in AD

I would like to use powershell to manage my user accounts in AD. I should write a script which will add a new user to AD. Can some one help me to write this script?

-PS would ask user's first name and last name (user name will firstname.lastname)
-PS asks company information and there would be numbers to choose it (1. company A, 2. company B, etc...)
-PS asks group memberships and there is number of roles to choose (so one role could contain multiple AD groups and one user could have multiple roles)
-PS asks which logon script would use and there would be list of numbers to choose again

Thank you very much :)
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

thaapavuoriAuthor Commented:
I forgot the OU. There should be one extra option to choose an OU. And again numbers of choices.

Chris DentPowerShell DeveloperCommented:

How do you want it to ask for all those things?

I'd have them all as command line parameters personally, but I guess you had something else in mind?

thaapavuoriAuthor Commented:
I found most of these command as well by myself. But my goal is that admin would click the scipt just once and this script would ask these questions and then this new user account would appear to AD. Im very new with PS so probably there is nothng difficult but Im not familiar to do it...

Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Chris DentPowerShell DeveloperCommented:

Ah click the script... that won't really be happening with PS unless you wrap it up in a batch file. Then writing a GUI for it is moderately hard work. It's a great command line language, much less easy for visual stuff.

What do you have so far?

thaapavuoriAuthor Commented:
i have created them manually untill now. we have just so many admins and there is big risk that some one does something wrong like accidentally
Chris DentPowerShell DeveloperCommented:

Mm yeah, I've been there :)

I guess it's important to retain instant account creation?

Hmm you'd almost be better with them filling in a little form and submitting that wouldn't you? It's possible to do that in PS, even if creating the form is a fair amount of messing around.

thaapavuoriAuthor Commented:
Yep, that is one great possibility as well.

Chris DentPowerShell DeveloperCommented:
It''s not easy to do unfortunately, it's far beyond the simple scripts you would need to create a user account.

Have you built anything for this yet?

thaapavuoriAuthor Commented:
No not really. But I can maybe use my collegue to do this. I was first planning to create just some simple script for this.

Chris DentPowerShell DeveloperCommented:

Which of these is most appropriate depends on how easy you want it to be for the scripts consumer (whoever is using it). Many consider command line based scripts unfriendly so they shy away from them.

The part of the script that actually does the work is rather simple. Creating users is well documented. Taking and validating user input, and presenting an interface for that is far harder.

From simple to complex:

1. Request values using Read-Host. e.g.

$OU = Read-Host -Prompt "Enter the OU"

2. Read input values as parameters

# Script.ps1
  $OU = "Some Default Value
# The rest of the script

# Calling the script:
./Script.ps1 -OU "Some non-default value"

3. Using a Form using .NET forms

Examples of this start here:

In my opinion you'd be better off designing a form in Visual Studio (Express) using either VB .NET or C# .NET then converting the code back down to PowerShell. Entirely possible but quite a lot of work and requires quite a lot of familiarity with .NET and PowerShell.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.