Skip to content

zdmilot/Powershell-New-User-Script

Repository files navigation

PowerShell New-ADUser Creation Script

Written by [Zachary Milot] (http://www.zdmilot.com/), with help from [William Stevens] (https://github.com/wastevensv)

Requirements

The following is required to run the script:

Prerequisite Description
Windows Server Have the ability to run at least PowerShell 2.0
PowerShell 2.0 or Greater Will run on PowerShell 2.0, but works best on 3.0
ActiveDirectory Module Comes with Windows Server

Quick Start

Getting started with the New-ADUser Creation Script is fast and easy once you have the prerequisites meet. Here are the steps:

  • Find the directory of the script
  • Right click the script and click run with PowerShell
  • Then follow all of the prompts soliciting you for input

If you see errors, make sure to check the part of the code that the error directs you to in order to fix the issue.

Script Breakdown

The breakdown below will give you a glimpse of what the script does.

###User Solicited Input

•Last Name Field

This solicits a user to define a single variable $First which turns into mutable variables inside of a loop, and checks if it contains a Jr. of jr and it makes a couple of copies of the variable if it does. The copies of the variable include $Last, which is the user imputed data but is later changed to just the last name without the Jr; $Last1 which contains Jr.; $Last2 that contains just the root name without Jr. (similar to $Last, but defined first); $LastE, the last name with Jr connected to the name for the email address; and lastly $LastD, which is the display name including Jr.

The script also checks if the last name contains a Mc or an O' like McDonanalds or O'Riley. This does similar things to the Jr. correcting code does, but on a smaller scale, because they are a part of the last name, and not something that has to be in one (ie display name and email) but not the other (ie last name).

This loop contains NO error correction, only separation for certain parts of the last name.

•First Name Field

This solicits a user to define the variable $First.

This loop contains NO error correction, and no separation for different parts of the name. It does however contain auto capitalization, but that is it (basically WYSIWYG).

•Middle Initial Field

This solicits the user to define the variable $MiddleI.

This loop contains NO error correction, but does only accept single character responses, with auto capitalization.

•Department Field [CHANGED IF DEPT. GET ADDED OR CHANGED]

This solicits the user to define the variable $Dept.

This loop CONTAINS error correction for abbreviations of a department.

•Job Title Field

This solicits the user to define the variable $Title.

This loop contains NO error correction, but has auto capitalization.

•Service Center Location Field

This solicits the user to define the variable $Local, which turns into mutable variables like $Local, which could be the same variable before, but it would be the abbreviation of a state like MA; $Address, which is the street address for that service center; $ServCity, which defines the service center's city; $Zip which defines the Zip code of the service center; $PhoneArea, which defines the first six characters of the phone number of the service center; $DeExt which defined the last four digits of the main telephone number for that service center; and $Fax which defines the fax number for the service center.

This loop CONTAINS error correction for input of a city or a state (sometimes a user must input a specific city if there are two in one state).

•Extension Field (OPTIONAL and COMMENED OUT)

This solicits the user to define the variable $Ext. This field is commented out, because normally a user of this script would not be able to provide an extension for a user, but it is here if needed in the future. This field only accepts four characters and would replace the last four digits of the phone number, previously defined in the service center location field as $DeExt.

This loop contains NO error correction, but only accepts four characters.

•Mobile Phone Field

This solicits the user to define the variable $MobilePh. This field is for users to be able to add a mobile phone number to a user’s profile if they have it.

This loop contains NO error correction for the data entered into the field, but only accepts 10 characters.

•Company Field

This solicits the user to define the variable $Company.

This loop CONTAINS error correction for input of an abbreviation of a company.

###Background User Creation and Solicitation for Confirmation

•User Displayed All Inputs to be Used to Create Account

After all the prompts have been properly answered the user is shown the final variables.

•Changing The Phone Numbers To Domain Norms

The next part of the script will take the mobile phone number, phone number, and fax, and remove the parentheses and dashes, and insert . like from (508) 966-6000 to 508.966.6000

•Conformation of Correct Information

At this point the user will have a "yes or no"" prompt that will ask them if all of the information is correct.

If they state that yes, it is correct: The loop will break and the information will be entered into following Cmdlets If they state that no, it is not correct: The loop will start over again

If Yes, Lets Move On:
•Z Drive Creation (only possible with PS3)

This will create a users Z drive, and set full control permissions to the user who's account will be attached to the folder.

•CSV Creation

Creates a log of what the person entered into the script, by placing a CSV file in a folder on the desktop. PowerShell 2 does not support -append during creation, so separate files have to be made in order for the script to make a log.

•Move User to Proper OU [CHANGED IF DEPT. GET ADDED OR CHANGED]

This is the field which places the user in an Organizational Unit in Active Directory, by changing the $Path variable which is used in the New-ADUser Cmdlet.

•New-ADUser Creation

This is the part of the script where all variables get imputed to create a user account. This shouldn't be changed, only appended, as these variables are predefined.

•If No Cell Phone

What this does, is if the user did not define a cell phone number it will change the description of the phone number to be no cell.

•Add Group Association For All Users

This part of the script will add group association like "General" and "Global" which is added to all users

•Add Group Association Based Upon Service Center Location

This part adds groups like "MA" or "FL" or "CT" to a users profile

•Add Group Association Based Upon Dept.[CHANGED IF DEPT. GET ADDED OR CHANGED]

This part adds a user to a specific group based upon there department.

•Adding A Mailbox Solicitation

This loop asks the user if they would like to add a users mailbox.

If yes: A users mailbox is enabled in exchange if the admin entering the new employees information has acces to exchange. If no: A users mailbox won't be created and the script will move once

•Displayed that the script has completed
•Asks The User If They Would Like to Add Another User

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published