Hello Support
Below script is kept in Windows Server R2 2012. particular path
How to execute or making to start from Windows 10 or Windows 11 PC (User Machine)
Because this script is for HR. Once they filled new employee details. how to execute this server script
Import active directory module for running AD cmdlets
Import-Module activedirectory
Store the data from ADUsers.csv in the $ADUsers variable
$ADUsers = Import-csv C:\temp\ADCreation\UserForm.csv
Loop through each row containing user details in the CSV file
foreach ($User in $ADUsers)
{
Read user data from each field in each row and assign the data to a variable as below
$Username = $User.username
$Password = $User.password
$Firstname = $User.firstname
$Lastname = $User.lastname
$OU = $User.ou
$Password = $User.Password
$telephone = $User.telephone
Check to see if the user already exists in AD
if (Get-ADUser -F {SamAccountName -eq $Username})
{
If user does exist, give a warning
Write-Warning "A user account with username $Username already exist in Active Directory."
}
else
{
User does not exist then proceed to create the new user account
#Account will be created in the OU provided by the $OU variable read from the CSV file
New-ADUser `
-SamAccountName $Username `
-UserPrincipalName "$Username@tls.local" `
-Name "$Firstname $Lastname" `
-GivenName $Firstname `
-Surname $Lastname `
-Enabled $True `
-DisplayName "$Firstname $Lastname" `
-Path $OU `
-OfficePhone $telephone `
-Office $office `
-AccountPassword (convertto-securestring $Password -AsPlainText -Force) -ChangePasswordAtLogon $True
}
}
Please advise