Windows Server 2012 R2: How-to add users and computers using PowerShell?

The following is a sample chapter from the e-Book Windows Server 2012 R2: How to setup your server? (Server Core). Enjoy reading!

“Virtuous action does not consist in doing good to someone who has done good to you—that is merely returning a favor. Virtuous action consists in doing good to those who have wronged you.” Jesus (pbuh)

What is AD DS?

AD DS is a distributed database which stores objects in a hierarchical, structured, and safe format. AD DS objects typically represent users, computers, peripheral devices and network services.

How AD DS works?

Any object is uniquely identified by its name and attributes. The domain, the forest, and the tree represent logical division of AD DS network. To ease the administration of objects, AD DS provides organizational units (OU).

How to add AD DS role?

In Windows Server 2012 R2 Server Core Server Core, the AD DS is offered as a role that can be added using PowerShell. To add the AD DS role to your server, complete the following steps:

  • login to your server by typing your Administrator’s password and pressing Enter
  • type PowerShell at command prompt and press Enter
  • type Install-windowsfeature AD-Domain-Services and press Enter
  • type Import-Module ADDSDeployment and press Enter

How to promote a server to a domain controller?

To promote a server to a domain controller using PowerShell, complete the following steps:

  • type Install-ADDSForest and press Enter
  • provide the name for the domain and press Enter
  • provide the safe mode administrator password and press Enter
  • confirm safe mode administrator password and press Enter
  • type letter Y for Yes and press Enter
  • after the installation is complete the server will restart automatically
  • login to your server by typing your Administrator’s password and pressing Enter
  • type sconfig.cmd and press Enter
  • you’ll notice that the domain is WS2012R2SC.local

figure6How to add a computer in AD?

In Windows Server 2012 R2 Server Core, a domain is a logical computer network comprised of user accounts, computers, printers and security settings. All this information is stored in a central database which resides in a domain controller. To add a computer in AD, complete the following steps:

[Complete the following steps in Client Computer (Win81PC1):]

  • right-click at the Start button and select Command Prompt (Admin)
  • at Command Prompt type PowerShell and press Enter
  • to add a local computer to a domain type Add-Computer -DomainName “WS2012R2SC.local” -Restart and press Enter

figure7

  • provide domain admin credentials such as username and password and press Enter or click OK

figure8

  • shortly your computer will restart
  • after the computer restart completes login to your computer (note the domain is available) and open up the Command Prompt window
  • at Command Prompt type PowerShell and press Enter
  • to get the FQDN (Fully Qualified Domain Name) type [System.Net.Dns]::GetHostByName(($env:Win81PC1))

figure9

How to add a user in AD?

To add a user in AD, complete the following steps:

[Complete the following steps in Domain Controller (WS2012R2SC):]

  • at the PowerShell prompt type New-ADUser -Name “Test User” -GivenName Test -Surname User -SamAccountName testuser -UserPrincipalName [email protected] and press Enter

figure10

  • to get properties of a testuser in AD type Get-ADUser testuser and press Enter

figure11

  • to set a password for a testuser in AD type Set-ADAccountPassword -Identity testuser -Reset -NewPassword (ConvertTo-SecureString -AsPlainText “PaSSw0rd” -Force) and press Enter

figure13

  • to enable a testuser in AD type Enable-ADAccount -Identity testuser and press Enter

figure14

[Complete the following steps in Client Computer (Win81PC1):]

  • if you are at the login screen click Other user to provide the testuser’s username and password to login to a WS2012R2SC.local domain and press Enter

figure12

  • the testuser account has signed in successfully into WS2012R2SC.local domain

figure15

Hope you’ll find this post informative.