Active Directory Home Lab. Part 4-Configuring DNS & DHCP on Domain Controller.

Kushal Sharma
7 min readNov 7, 2023

--

Creating Users in Active Directory

To create multiple users in Active Directory, we will use a PowerShell script. The script will automate the user creation process. By using the script, we can avoid manually creating a large number of users. This saves time and effort. The script will generate sample users for testing purposes.

Steps to Create Users using PowerShell Script
1. Run the PowerShell script to create users in Active Directory.
2. The script will generate a specified number of sample users.
3. These users can be used for testing and demonstration purposes.
4. Manually creating users is time-consuming, so the script is a more efficient solution.
5. The script automates the user creation process, saving time and effort.

Creating Users Programmatically

To create users programmatically, follow these steps:

1. Open the file containing the list of randomized names.
2. Add your own name at the top of the list for realism.
3. Save and close the file.
4. Click on the “Start” button.
5. Go to “Windows PowerShell”.
6. Right-click on “Windows PowerShell” and select “Run as administrator”.
7. Click “Yes” to allow the program to run with administrative privileges.
8. In the PowerShell window, click on “Open” and navigate to the folder where the PowerShell script is located.
9. Open the PowerShell script.

Enabling Execution of Scripts on the Server
To enable the execution of all scripts on the server, follow these steps:

1. Open the command prompt or PowerShell on the server.
2. Run the following command: Set-ExecutionPolicy Unrestricted
3. When prompted, confirm the action by typing Y and pressing Enter.

Note: Enabling the execution of all scripts is a security risk, so exercise caution when using this setting.

But, because we are running this in a lab environment, it is essential to perform the above step to successfully run the PowerShell script.

- The script will read the list of names from the file.
- It will iterate through each name in the list.
- For each name, it will create a user programmatically.
- Finally, it will display a message indicating the successful creation of the users.

Here’s the PowerShell Script used:

# — — — Edit these Variables for your own Use Case — — — #
$PASSWORD_FOR_USERS = “Password1”
$USER_FIRST_LAST_LIST = Get-Content .\names.txt
# — — — — — — — — — — — — — — — — — — — — — — — — — — — #

$password = ConvertTo-SecureString $PASSWORD_FOR_USERS -AsPlainText -Force
New-ADOrganizationalUnit -Name _USERS -ProtectedFromAccidentalDeletion $false

foreach ($n in $USER_FIRST_LAST_LIST) {
$first = $n.Split(“ “)[0].ToLower()
$last = $n.Split(“ “)[1].ToLower()
$username = “$($first.Substring(0,1))$($last)”.ToLower()
Write-Host “Creating user: $($username)” -BackgroundColor Black -ForegroundColor Cyan

New-AdUser -AccountPassword $password `
-GivenName $first `
-Surname $last `
-DisplayName $username `
-Name $username `
-EmployeeID $username `
-PasswordNeverExpires $true `
-Path “ou=_USERS,$(([ADSI]`””).distinguishedName)” `
-Enabled $true
}

By following these steps and running the PowerShell script, you will be able to create users programmatically using the list of names.

Running the Script
To run the script, follow these steps:

1. Open the command prompt or PowerShell on the server.
2. Navigate to the directory where the script is located.
3. Just type cd C:\users\a-ksharma\desktop\AD_PS-master in the prompt.
4. Run the script by typing
C:\users\a-ksharma\desktop\AD_PS-master\”File Name” and pressing Enter.

The code provided splits an input string into an array, extracts the first and last name from the array, and creates a username using the first character of the first name. It then loops through a thousand users, performing user-specific operations within each iteration.

After executing the above command, you can now see a list of users being created from the script we ran. It’s going to take a minute to load all the users.

You can also check to confirm if the users were created by going to Active Directory Users and Computers (Tools) in Server Manager > Right Click on Domain & Refresh > _USERS(Just Created).

Also by Right Click on Domain > Find > Find (Users, Contacts and Groups) > Find Now. You can see all the users that were created as a Result of this PowerShell script.

Conclusion
In this section, we learned how to enable the execution of all scripts on the server and briefly explained the structure and purpose of the script. Now, we can proceed to run the script.

Let’s take a quick look at the network diagram to understand the overall setup of our environment.

The last thing we have left to do is to set up a Windows 10 Virtual Machine in VirtualBox. It will get it’s IP Address from the DC we created through DHCP(configured).

Setting up a Windows 10 Virtual Machine in VirtualBox

To set up a Windows 10 virtual machine in VirtualBox, follow these steps:

1. Open VirtualBox and click on “New” to create a new virtual machine.
2. Name the virtual machine as “Client 1” or any desired name.
3. Select “Windows 10 64-bit” as the operating system for the virtual machine.
4. Allocate enough RAM for the virtual machine. It is recommended to allocate at least 4 gigabytes of RAM, but if you have limited resources, you can allocate 2 gigabytes.
5. Continue with the default settings for the virtual machine.
6. Before proceeding, make sure that your internet connection is set up and connected.
7. Set up the network configuration for the virtual machine:
-Use an internal NIC (Network Interface Card) for the virtual machine.
-Instead of using the home network, select the internal network adapter.
- This allows us to connect to the domain controller and simulate a corporate network.
- Go to Settings > Network > Adapter.
- Choose the internal network adapter option instead of NAT.
-
The virtual machine should obtain its IP address from the DHCP server that you have configured.

8. After completing the virtual machine setup, you can minimize the domain controller window as it is not needed at the moment.
9. Go back to VirtualBox and start the virtual machine.

Now, you have successfully set up a Windows 10 virtual machine in VirtualBox. You can proceed with further verification and configuration if needed.

- Double-click on the client to open it.
- If it opens on a different screen, move it to the desired location.

## Step 5: Adding Additional Clients
- Check the client settings.
- Click on “Add” to add more clients.

# Installing Windows 10

To install Windows 10, follow these steps:

1. Locate the Windows 10 ISO file that you downloaded earlier. If you saved it on the desktop, browse to the desktop.
2. Select the Windows 10 ISO file and click on “Choose” to proceed.

3. Click on “Start” to begin the installation process. Note that this may take some time.
4. Click on “Next” and then select “Install” to continue.
5. Choose the option “I don’t have a product key” and do not select the “Home” edition, as it does not allow joining a domain.
6. Select “Windows 10 Pro” and click on “Next”.
7. Accept the terms and conditions by clicking on “Next”.
8. Choose the “Custom” option since the hard drive is empty, and then click on “Next” to proceed with the installation.
9. The installation process may take a while. The computer may restart multiple times during this process.
10. Once the installation is complete, the computer will restart again and prompt you to perform additional setup steps. Do not press any buttons during this time.

Windows Setup Configuration

User Configuration
- Select “Yes” for the option “United States” if prompted.
- If asked about internet connection, choose “I don’t have internet” and proceed with limited setup.
- Avoid creating a Microsoft account and instead choose to create a local account.
- Set the local username as “user” (or any desired name).
- No password is required for the local account.
- It’s going to take a while to install the OS. Be patient.

Now, the first thing we need to do is to make sure the Internet is working as we configured it (refer to the network diagram).

Troubleshooting Internet Connection

To troubleshoot internet connection, follow these steps:

  1. Click on the Start button and open the command line.
    2. Type “ipconfig” and press Enter.
    — Check if you have an IP address.

A ping to 8.8.8.8 is resolved and a reply is received which indicates that our DNS is working.

--

--

No responses yet