Files
Powershell-Training/3.Active_Directory/Learn Powershell with Active Directory in Less than 2 hours.md

3.0 KiB

Learn Powershell with Active Directory in Less than 2 Hours

Windows Server

Windows Server is a Microsoft operating system designed to manage networks, users, and applications in a business environment. It provides services such as file sharing, security management, and server hosting to support reliable and centralized IT operations.

Active Directory

Active Directory (AD) is a directory service developed by Microsoft that helps organizations manage and organize users, computers, and other resources within a network. It allows administrators to control access, enforce security policies, and manage permissions from a central location.

Import-Module

Before using active Directory with Powershell we have to imports the cmdlet

Import-Module ActiveDirectory
Get-Command -Module ActiveDirectory

Get-Help

To see all the options for one command

Get-Help New-ADUser

OU

An Organizational Unit (OU) is a container in Active Directory used to organize users, computers, and groups within a domain. It helps administrators manage resources more efficiently by grouping objects based on departments, roles, or locations.

New-ADOrganizationalUnit

New-ADOrganizationalUnit -Name "ROCK" -Path "DC=mrsh,DC=org"
New-ADOrganizationalUnit -Name "Staff" -Path "OU=ROCK DC=mrsh,DC=org"
New-ADOrganizationalUnit -Name "Students" -Path "OU=ROCK DC=mrsh,DC=org"
New-ADOrganizationalUnit -Name "LedZep" -Path "OU=Students OU=ROCK DC=mrsh,DC=org"
New-ADOrganizationalUnit -Name "Cream" -Path "OU=Students OU=ROCK DC=mrsh,DC=org"
New-ADOrganizationalUnit -Name "Who" -Path "OU=Students OU=ROCK DC=mrsh,DC=org"
New-ADOrganizationalUnit -Name "Hendrix" -Path "OU=Students OU=ROCK DC=mrsh,DC=org"

Users

In Active Directory, users are directory objects that represent individual people or service accounts and are used to authenticate and authorize access to network resources. Each user account contains attributes such as a username, password, group memberships, and profile information, which allow administrators to manage identity, security, and permissions centrally. Through Active Directory, users can log on to domain-joined computers, access shared files, applications, and services, and inherit permissions based on their group assignments, making user management more efficient, secure, and scalable in enterprise environments.

New-ADUser

For creating a new user

New-ADUser -Name "Jimmy Page" -SamAccountName "jpage" -UserPrincipalName "jpage@mrsh.org" 
`-Path "OU=Rock , OU=Students, OU=LedZep, DC=mrsh, DC=org" -AccountPassword (ConvertTo-SecureString "Music123" -AsPlainText -force) -Enabled $true

Get-ADUser

For fetching informations about a user

Get-ADUser -Identity "jpage"
Get-Aduser -Filter 'Enabld -eq $true'

#setting a varialbe to a user

$ADUser = Get-ADUser -Identity "jpage"
$ADUser.UserPrincipalName

# return
# jpage@mrsh.org

$ADUser = Get-Aduser -Identity "jpage" | Select-Object Name,SamAccountName,UserPrincipalName