Windows PowerShell: Working with Active Directory
Windows PowerShell: Working with Active Directory
One thing I will say here. I was teaching a class and I had a brain fart. I couldn’t for the life of me remember how to add users to groups. Well one little nuance to the above script is adding multiple users requires you to do an assignment first. You do it in one of these two ways.
Method 1 $group=[adsi]”LDAP://path”; foreach-object ($user in $userarray) { $user; $null=$group.member.add($user); } $group.psbase.commitchanges(); |
or in this method we use the pipeline instead, however you have to assign it to a variable first.
Method 2 $group=[adsi]”LDAP://path”; $userarray | foreach-object { $user=$_; $user; $null=$group.member.add($user); } $group.psbase.commitchanges(); |
When it comes to working with PowerShell and ADSI, it is important to refer back to these two blog posts.
http://blogs.technet.com/benp/archive/2007/03/05/benp-s-basic-guide-to-managing-active-directory-objects-with-powershell.aspx
and
These that are related
http://pathologicalscripter.wordpress.com/2006/09/28/invisible-methods-for-adsi/
http://blogs.msdn.com/arulk/archive/2006/07/25/678137.aspx
http://blogs.msdn.com/arulk/archive/2006/07/28/682289.aspx
http://blogs.msdn.com/arulk/archive/2006/08/24/719241.aspx
And when needing a reference to set values, here is the guide that showed which interface and what are the right fields in active directory.
http://msdn.microsoft.com/en-us/ms677286.aspx