Add OU , User, Computer

  # List DistinguishedName

Get-ADDomain | Select-Object -ExpandProperty DistinguishedName
Copied!

  # Create OU and Sub OU

# Create parent OU
New-ADOrganizationalUnit -Name "Team" -Path "DC=tbk,DC=kh"

# Create child OUs under Team
New-ADOrganizationalUnit -Name "Controll all" -Path "OU=Team,DC=tbk,DC=kh"
New-ADOrganizationalUnit -Name "Computer" -Path "OU=Team,DC=tbk,DC=kh"
New-ADOrganizationalUnit -Name "User" -Path "OU=Team,DC=tbk,DC=kh"
Copied!

  # Rename OU

# Rename "Controll all" to Group
Rename-ADObject `
  -Identity "OU=Controll all,OU=Team,DC=tbk,DC=kh" `
  -NewName "Group"
Copied!

  # Delete OU Group

Set-ADOrganizationalUnit `
  -Identity "OU=Group,OU=Team,DC=tbk,DC=kh" `
  -ProtectedFromAccidentalDeletion $false

Remove-ADOrganizationalUnit -Identity "OU=Group,OU=Team,DC=tbk,DC=kh"
Copied!

  # List All OU

Get-ADOrganizationalUnit -Properties CanonicalName -Filter * | Select-Object CanonicalName, DistinguishedName
Copied!

  # Create User

New-ADUser `
  -Name "WIN7" `
  -SamAccountName "WIN7" `
  -AccountPassword (ConvertTo-SecureString "1" -AsPlainText -Force) `
  -Path "OU=User,OU=Team,DC=tbk,DC=kh" `
  -Enabled $true `
  -PasswordNeverExpires $true
Copied!

  # List All USER

Get-ADUser -Properties CanonicalName -Filter * | Select-Object CanonicalName, DistinguishedName
Copied!

  # Create Computer

New-ADComputer `
  -Name "WINDOWS7" `
  -Path "OU=Computer,OU=Team,DC=tbk,DC=kh"
Copied!

  # List All COMPUTER

Get-ADComputer -Properties CanonicalName -Filter * | Select-Object CanonicalName, DistinguishedName
Copied!

  # Create the group

New-ADGroup `
  -Name "Group of user" `
  -GroupScope Global `
  -GroupCategory Security `
  -Path "OU=Team,DC=tbk,DC=kh"
Copied!

  # List All GROUP

Get-ADGroup -Properties CanonicalName -Filter * | Select-Object CanonicalName, DistinguishedName
Copied!