Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade
Active Directory (AD) is a directory service developed by Microsoft for Windows domain networks. It is a crucial component for managing users, computers, and other devices within a network. This article will guide you through managing Active Directory using PowerShell, a powerful scripting language and command-line shell for task automation and configuration management.
Active Directory provides a variety of services, including:
Before you start, ensure you have:
To manage AD using PowerShell, you need to install the Active Directory module. Here's how:
Install-WindowsFeature -Name RSAT-AD-PowerShell
To create a new user in Active Directory, use the New-ADUser
cmdlet. Here’s an example:
New-ADUser -Name "John Doe" -GivenName "John" -Surname "Doe" -SamAccountName "jdoe" -UserPrincipalName "jdoe@domain.com" -Path "OU=Users,DC=domain,DC=com" -AccountPassword (ConvertTo-SecureString "P@ssw0rd" -AsPlainText -Force) -Enabled $true
To modify user properties, use the Set-ADUser
cmdlet. For example, to change the user’s title:
Set-ADUser -Identity "jdoe" -Title "Manager"
To delete a user, use the Remove-ADUser
cmdlet:
Remove-ADUser -Identity "jdoe"
To create a new OU, use the New-ADOrganizationalUnit
cmdlet:
New-ADOrganizationalUnit -Name "Sales" -Path "DC=domain,DC=com"
To search for users, use the Get-ADUser
cmdlet. For example, to find all users with the name "John":
Get-ADUser -Filter {GivenName -eq "John"}
To create multiple users from a CSV file, use the following script:
Import-Csv -Path "C:\Users\ListOfUsers.csv" | ForEach-Object {
New-ADUser -Name $_.Name -GivenName $_.GivenName -Surname $_.Surname -SamAccountName $_.SamAccountName -UserPrincipalName $_.UserPrincipalName -Path $_.Path -AccountPassword (ConvertTo-SecureString $_.Password -AsPlainText -Force) -Enabled $true
}
To reset a user’s password, use the Set-ADAccountPassword
cmdlet:
Set-ADAccountPassword -Identity "jdoe" -NewPassword (ConvertTo-SecureString "NewP@ssw0rd" -AsPlainText -Force) -Reset
Managing Active Directory using PowerShell provides a powerful and flexible way to automate administrative tasks. By mastering these cmdlets, you can efficiently manage your AD environment, saving time and reducing the potential for human error.