Category Archives: Howto Tutorials (EN)

Howto Tutorials English Contribution Howto’s and Tutorials technical contribution for Professionals

Add Active Directory user in PowerShell from CSV-file

Automatically create users with New-AdUser from Import-CSV file

If a large number of users is to be created automatically in Active Directory, PowerShell is also the appropriate way to go, create multiple Active Directory user objects with New-AdUser via Import-Csv.

This tutorial shows how to use of New-AdUser for automated user creation, by importing object data from a CSV file with Import-Csv.

When migrating where parts of users from an organizational unit (OU) are transferred from an Active Directory forest to a new or different forest, the Active Directory modules are suitable for user management, with the cmdlet “Get-AdUser” as well as for creating new accounts with “New-AdUser“. A total of around 50 parameters are supported whose names match the attributes in the AD.

A simple command could look like this if you have a new user with the SamAccountNameSebastian“.

$Password = Read-Host "Enter a Password" -AsSecureString
New-AdUser -Name Sebastian -GivenName Sebastian -Surname Furrer -Path "OU=User,OU=Office,DC=Company,DC=com" -Enabled $True -AccountPassword $Password -ChangePasswordAtLogon $True

The command creates a user and apply the AccountPassword parameter to set a password that was previously entered. Numerous other attributes with values can be applied. For a simple user creation, this example is already sufficient to the user are able to authenticate against active directory.

User export and import via CSV file

The users can be exported from the OU to a CSV file by using filters, which is then available for the user import, this for the next step to the intended target organizational unit.

Get-AdUser -Filter * -SearchBase "OU=User,OU=Office,DC=Company,DC=com" | Export-Csv -Path .\users.csv -NoClobber -Delimiter ";"

With a large number of users, you will not want to create them individually. The best way to import data contains a list of object properties from the CSV file is to do this. The prerequisite must be met that the column headings in the CSV file exactly match the names of the parameters. A file exported with Export-Csv might look something like this.

User export and import via CSV file

  If the export has been formatted with a comma as a delimiter, specify import-csv with delimiter via parameter -Delimiter.

A foreach loop creates the users in the specified OU context.

$Import = Import-CSV ".\users.csv" -Delimiter ";"
$OU = "OU=User,OU=Office,DC=Company,DC=com"
$Password = ConvertTo-SecureString "Initpass" -AsPlainText -Force

foreach ($user in $Import) {
  New-ADUser -Name $user.SamAccountName -GivenName $user.GivenName -Surname $user.Surname -Path $OU -AccountPassword $Password -ChangePasswordAtLogon $True -Enabled $True -UserPrincipalName $user.UserPrincipalName

Run the command-lines in PowerShell in the same directory where the exported CSV file (“users.csv“) is located, or apply the appropriate path with the -Path parameter.

Windows PowerShell ISE New-AdUser

As soon as the newly created user logs on to AD, he is prompted to enter a new password, which replaces the initial password (“Initpass“).


The Active Directory cmdlet New-ADUser makes it easy to create multiple Active Directory users. Frequently used user property values can be set with parameters. Using the Import-Csv with New-ADUser cmdlet, it is possible to create a large number of Active Directory user objects. The custom objects are created from a comma-separated CSV file that contains a list of object properties. The objects are piped to New-ADUser to create the user objects with attributes. The help is output with get-help New-ADUser.

How to Upgrade PHP on Debian 9 10 11

Upgrade or Install PHP 8.1 on Debian running Apache2

This tutorial shows how to install or upgrade PHP 8.1 quick and easy for Apache web server running on Debian 9 or Debian 10 and Debian 11. PHP is the widely used server scripting language for dynamic and interactive websites and content management systems.

5 steps to perform PHP 8.1 for Apache2 on Debian.

1. Updating Debian as root

$ su -
$ apt update
$ apt upgrade -y && reboot

2. Add SURY PHP PPA Repository

SURY is a third-party repository that offers current PHP versions for Debian GNU/Linux, which is added as root.

$ apt -y install lsb-release apt-transport-https ca-certificates
$ wget -O /etc/apt/trusted.gpg.d/php.gpg
$ echo "deb $(lsb_release -sc) main" | tee /etc/apt/sources.list.d/php.list

3. Installing PHP 8.1 on Debian

$ apt update
$ apt -y install php8.1
$ update-alternative --set php /usr/bin/php8.1

More than one PHP version can be installed on the system, run update-alternatives --set php [version] to enable a Version.

4. Install Important Modules for PHP 8.1 on Debian

$ apt -y install php8.1-cli php8.1-curl php8.1-gd php8.1-intl php8.1-mbstring php8.1-mysql php8.1-opcache php8.1-readline php8.1-xml php8.1-xsl php8.1-zip php8.1-bz2

5. Making PHP 8.1 module for Apache available

$ apt -y install libapache2-mod-php8.1
$ systemctl reload apache2

Finish! the installation is done. If you want to know which installed PHP version and modules are actually available, the next section shows.

Check the current PHP version

$ php -v
PHP 8.1.1 (cli) (built: Dec 20 2021 21:33:24) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.1, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.1, Copyright (c), by Zend Technologies

Show current PHP configuration

The current PHP settings are displayed by creating a .php-file with the following content, to output the detailed settings in the web browser.


Save the file as phpinfo.php in the “/html” directory. Then open the newly created .php-file in a web browser.

view phpinfo in web browser
Image: http://my-domain/phpinfo.php

The system-wide PHP settings can be found under the path /etc/php, for modification using Apache 2 edit the php.ini file.

$ vi /etc/php/8.1/apache2/php.ini

If you do not see the installed php version, may the apache php module need to change to the desired version, run the apache helper command in the terminal, replace the version you have instead, like here php.7.3 in this example.

$ a2dismod php7.4
$ a2enmod php8.1
$ systemctl restart apache2

Verify the running php module with view the phpinfo.php from the web browser.

The PHP modules available for Apache 2 can find in the Apache web server path under /etc/apache2/mods-available.

$ ll /etc/apache2/mods-available/php*
-rw-r--r-- 1 root root 855 Jul  5  2020 /etc/apache2/mods-available/php7.3.conf
-rw-r--r-- 1 root root 102 Jul  5  2020 /etc/apache2/mods-available/php7.3.load
-rw-r--r-- 1 root root 855 Dec 20 22:32 /etc/apache2/mods-available/php7.4.conf
-rw-r--r-- 1 root root 102 Dec 20 22:32 /etc/apache2/mods-available/php7.4.load
-rw-r--r-- 1 root root 855 Dec 20 22:32 /etc/apache2/mods-available/php8.1.conf
-rw-r--r-- 1 root root 101 Dec 20 22:32 /etc/apache2/mods-available/php8.1.load

Disable an Apache 2 module with a2dismod, use a2enmod to enable. The apt info command provides information about module information.

$ apt info libapache2-mod-php8.1