PowerShell cmdlets for Active Directory (AD) with examples

 Here are some of the common PowerShell cmdlets for Active Directory (AD) with examples:


  1. Get-ADUser: This cmdlet is used to retrieve information about a specific user or all users in an AD domain. Example: Get-ADUser -Identity "John Doe"

  2. New-ADUser: This cmdlet is used to create a new user in an AD domain. Example: New-ADUser -Name "Jane Doe" -GivenName "Jane" -Surname "Doe" -SamAccountName "jane.doe" -UserPrincipalName "jane.doe@contoso.com" -Path "CN=Users,DC=contoso,DC=com" -AccountPassword (ConvertTo-SecureString "P@ssword1" -AsPlainText -Force) -Enabled $True

  3. Set-ADUser: This cmdlet is used to modify an existing user in an AD domain. Example: Set-ADUser -Identity "Jane Doe" -Description "Marketing Manager"

  4. Remove-ADUser: This cmdlet is used to delete a user in an AD domain. Example: Remove-ADUser -Identity "Jane Doe" -Confirm:$False

  5. Get-ADGroup: This cmdlet is used to retrieve information about a specific group or all groups in an AD domain. Example: Get-ADGroup -Filter * -SearchBase "CN=Users,DC=contoso,DC=com"

  6. New-ADGroup: This cmdlet is used to create a new group in an AD domain. Example: New-ADGroup -Name "Marketing Team" -GroupCategory Security -GroupScope Global -Path "CN=Users,DC=contoso,DC=com"

  7. Set-ADGroup: This cmdlet is used to modify an existing group in an AD domain. Example: Set-ADGroup -Identity "Marketing Team" -Description "Marketing Department Team"

  8. Remove-ADGroup: This cmdlet is used to delete a group in an AD domain. Example: Remove-ADGroup -Identity "Marketing Team" -Confirm:$False

  9. Add-ADGroupMember: This cmdlet is used to add a member to a group in an AD domain. Example: Add-ADGroupMember -Identity "Marketing Team" -Members "Jane Doe"

  10. Remove-ADGroupMember: This cmdlet is used to remove a member from a group in an AD domain. Example: Remove-ADGroupMember -Identity "Marketing Team" -Members "Jane Doe"

These are just a few of the many AD-related cmdlets available in PowerShell. The above examples should give you a good idea of how to use these cmdlets to manage users and groups in an AD domain.

No comments:

Post a Comment