PowerShell Active Directory ADSI question
Posted: Thu Aug 30, 2018 7:31 am
Hello,
I notice then getting an Group object via ADSI as follows
$GroupDN = Get-AdGroup TestGroup01 | Select-Object -ExpandProperty Distinguishedname
$Group = [ADSI]”LDAP://$GroupDN”
The .Add method no longer appears to exist (using Winows Server 2012 R2 with PowerShell v4)
Therefore using reflection as follows
$User = “CN=Jane,CN=Users,DC=LAB,DC=pri”
$NativeComObject = $Group.psbase.NativeObject
[System.__ComObject].InvokeMember(“member”,[System.Reflection.BindingFlags]::SetProperty,$null,$NativeComObject,$User)
$Group.commitchanges()
The above adds Jane to the group but removes all other members, (basically I am setting the value of the member attribute to Jane and that is all, hence removing the other users)
What is the correct syntax to add Jane but not remove the other members please
I am sure Jim will know the answer to this is he still contrabutes to this forum
Thanks
I notice then getting an Group object via ADSI as follows
$GroupDN = Get-AdGroup TestGroup01 | Select-Object -ExpandProperty Distinguishedname
$Group = [ADSI]”LDAP://$GroupDN”
The .Add method no longer appears to exist (using Winows Server 2012 R2 with PowerShell v4)
Therefore using reflection as follows
$User = “CN=Jane,CN=Users,DC=LAB,DC=pri”
$NativeComObject = $Group.psbase.NativeObject
[System.__ComObject].InvokeMember(“member”,[System.Reflection.BindingFlags]::SetProperty,$null,$NativeComObject,$User)
$Group.commitchanges()
The above adds Jane to the group but removes all other members, (basically I am setting the value of the member attribute to Jane and that is all, hence removing the other users)
What is the correct syntax to add Jane but not remove the other members please
I am sure Jim will know the answer to this is he still contrabutes to this forum
Thanks