With following script I'd like to add a group to an AD user, but it doesn't do it, and I get no error.
param($Userid,$AdditionalGroup)
# Get user
$User = Get-ADUser `
-Filter "SamAccountName -eq $Userid"
# Add comment
Add-ADGroupMember `
-Identity $AdditionalGroup `
-Members $User
Filtering like that didn't work for me (and generated an error), however adding '
before and after $Userid did the trick.
param($Userid,$AdditionalGroup)
# Get user
$User = Get-ADUser `
-Filter "SamAccountName -eq '$Userid'"
# Add comment
Add-ADGroupMember `
-Identity $AdditionalGroup `
-Members $User