Create a script in windows PowerShell to add active directory users. Your script
ID: 3732946 • Letter: C
Question
Create a script in windows PowerShell to add active directory users. Your script needs to do the following (SEE BELOW FOR HINTS):
-It will start off by asking how many users you’d like to add (Hint- store the value entered as a variable called $number)
-Next, you’ll use a while loop
-In the while loop you’ll need to ask the user for an input of each of the switch parameters (the parameters with a – before them)
you’ll need a variable for name, given name, surname, user principal name and sam account name.
-after getting values for each of these variables from the user, your while loop will need to build the user in using New-ADuser, but you’ll need to use the variables as the parameters.
-your while loop will then need to prompt for a password and then you’ll need to set the password to the user.
-Finally, your while loop will need to enable the active directory account you just created.
Hints:
-Figure out how to store the user input number as a variable.
-Figure out how to capture user input and store as variables (like what you did above for the user input number) then pass these variables as parameters. As an example, ask your user to type in the account name and save it as $name.
Then, when you run New-ADUser use the parameter -name $name. DO THIS FOR ALL OF THE PARAMETERS NEEDED TO ADD A USER, not just name.
-Next, figure out how to create a while loop that starts with a number ($number) and decreases by 1 until it reaches zero.
-once you know how to do these 3 things, complete your script- first prompt for the number of users, then run your while loop (starting with $number and subtracting 1 each time until you reach zero). In the while loop you’ll prompt for user input of each of the parameter variables, then you’ll use those variables to add a user using New-ADUser.
-Prompt the user for a password, then assign the password to the user and enable the account.
Explanation / Answer
@echo off
setlocal enabledelayedexpansion
title Create new user
echo # of users you want to add?
set /p limit=""
set /p count="1"
echo !limit!
echo !count!
for /L %%A IN (1,1,3) Do
(
echo Name:
set /p name=""
echo User Name:
set /p username=""
echo Surname:
set /p surname=""
echo User Principal Name:
set /p principalname=""
echo Account Name:
set /p accname=""
echo User Created with the user name !username! Principal Name !principalname! and Account name !accname!
)
pause
exit
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.