1 | initial version |
The process for selecting particular groups to copy to a user using PowerShell involves the following steps:
Open PowerShell with administrative privileges.
Use the Get-ADUser commandlet to retrieve the user’s information.
Use the Get-ADGroup commandlet to retrieve the groups that you want to copy to the user.
Use the Add-ADGroupMember commandlet to add the user to the selected groups.
Confirm that the user has been added to the groups by running the Get-ADPrincipalGroupMembership commandlet.
Close PowerShell.
Here’s an example code snippet that shows how to copy particular groups to a user:
# Get the user’s information
$user = Get-ADUser -Identity username
# Retrieve the groups that you want to copy to the user
$groups = Get-ADGroup -Filter 'Name -like "groupname*"'
# Add the user to the selected groups
foreach ($group in $groups) {
Add-ADGroupMember -Identity $group -Members $user
}
# Confirm that the user has been added to the groups
Get-ADPrincipalGroupMembership -Identity $user