Active Directory (AD) is a directory service developed by Microsoft for managing users, groups, computers, and other resources in a networked environment. PowerShell is a powerful scripting and automation tool that can be used to manage Active Directory. Here are some basic PowerShell commands and tasks for managing Active Directory:
Note: To run Active Directory-related PowerShell commands, you typically need to have the Active Directory module installed and be a member of the appropriate Active Directory security groups. Additionally, ensure that you are running PowerShell with administrative privileges.
Get information about a specific user
Get-ADUser -Identity username
Create a new user
New-ADUser -Name “John Doe” -SamAccountName “johndoe” -UserPrincipalName “johndoe@yourdomain.com” -Path “OU=Users,DC=yourdomain,DC=com” -AccountPassword (ConvertTo-SecureString “Password123” -AsPlainText -Force) -Enabled $true
Reset a user’s password
Set-ADAccountPassword -Identity username -NewPassword (ConvertTo-SecureString “NewPassword123” -AsPlainText -Force)
Disable a user account
Disable-ADAccount -Identity username
Enable a user account
Enable-ADAccount -Identity username
Add a user to a group
Add-ADGroupMember -Identity “GroupName” -Members “username”
Remove a user from a group
Remove-ADGroupMember -Identity “GroupName” -Members “username”
Search for users based on specific criteria
Get-ADUser -Filter {Name -like “John*”}
Create a new group
New-ADGroup -Name “NewGroup” -GroupScope Global -GroupCategory Security
These are some basic PowerShell commands for managing Active Directory. You can perform a wide range of tasks using PowerShell, from user management to group management and more, depending on your specific requirements. Always exercise caution and follow best practices when making changes to your Active Directory environment.