Add-EADUsertoMultipleSecurityGroups

  • 8 June 2017
  • harringg
Description: 

Allows you select from multiple security groups and add user to them "at once" (foreach-object)

Language: 
Powershell
#keyword: GROUPS, UPDATES, USER
#[Modified, 1/18/2017 4:56 PM, Grant Harrington]
$UserName = read-host "User Name (sAMAccountName)"
$UserObject = Get-ADUser -Identity $UserName
 
#Initialize GROUPS_Global variable
."C:\Users\grant.harrington\Documents\SCRIPTS\GIT\Powershell\EAD\ADUC\GROUPS\Get-GlobalADGroups.ps1"
 
# This will present a "pop-up" (Out-GridView) listing the Names of the Security Groups
# Select (ctrl-click for multiple) Groups desired and Click OK
# This process will populate the $SecurityGroup Variable
 
$SecurityGroup = $GROUPS_Global | Select Name,SamAccountName | Out-GridView -PassThru
 
#Add User to specific SecurityGroup(s)
 
$SecurityGroup.sAMAccountName |
ForEach-Object {
$UserObject.sAMAccountName | Add-ADPrincipalGroupMembership -MemberOf $SecurityGroup.sAMAccountName
}
Note: that all applications posted here are posted for use, both commercial and non-commercial, free of charge, and as such are provided without warranty of any kind whatsoever. FMSCUG or any program's author are not responsible for any damages or shortcomings that result from usage of any of these applications.