How to Excute powershell script file of ActiveDirectory Server from Windows 10 or Windows 11

Sathishkumar Singh 486 Reputation points
2022-03-07T13:53:40.44+00:00

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

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,389 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Andreas Baumgarten 97,566 Reputation points MVP
    2022-03-07T14:59:40.227+00:00

    Hi @Sathishkumar Singh ,

    you need to install the RSAT tools on the client computer:
    https://technoresult.com/how-to-install-rsat-active-directory-in-windows-11/

    ----------

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten