User To Ad
User To Ad
can use the New-ADUser cmdlet. Below is a sample script to add a new
user to Active Directory. It assumes you have the appropriate
permissions to add users to your domain and that the Active Directory
module for PowerShell is installed.
PowerShell Script to Add a User to Active Directory
powershell
Copy code
# Import the Active Directory module (if not already loaded)
Import-Module ActiveDirectory
# Output confirmation
Write-Host "User $userUsername has been created successfully."
Explanation of the Script:
1. Import-Module ActiveDirectory: Ensures the Active Directory
module is available in the current session. (The module is part of
RSAT tools, and you need it to run AD-related cmdlets).
2. User Details: The script uses variables to define the user's details
such as:
o First name, last name, username, password, email,
description, etc.
o Modify these variables with the correct values for your new
user.
3. New-ADUser: The cmdlet used to create a new user in Active
Directory. The parameters:
o SamAccountName: The username that is used for login.