PowerShell and QADGroupPowerShell and QADGroupA company called Quest provides an extra snap-in for PowerShell. The idea is for these Active Directory cmdlets to work alongside the native PowerShell commands. As a result we can examine groups in general, and add members in particular. Incidentally, all the PowerShell and QAD nouns are singular, hence QADGroup (and not QADGroups) Topics for PowerShell's QADGroup and QADGroupMember
♣ Pre-requisites, particularly for the QAD snap-inBefore we can get my examples to work you need to meet these pre-requisites.
Example 1: Research the QADGroup Family of Cmdletsget-Command | Where {$_.name -match "QADGroup"} Note 1: The point of this command is to reveal the two branches of this family, QADGroup and QADGroupMember. get-QADGroup, new-QADGroup and set-QADGroup Example 2: Getting to know QADGroup parametersHere is the classic PowerShell method to discover the parameters of cmdlet.
The format is: get-help add-QADGroupMember Note 1: The two parameters of most interest are -identity and -member. If we reflect that the main verb is 'add', then we can see that -identity defines the group object itself, while -member takes care of the user(s) we are adding to this group. Example 3: Listing the Users in a GroupLet us assume that you have fulfilled the above pre-requisites, now there are just three things to do before my next script will work: a) Connect to Active Directory, best would be to logon at a domain controller in a test network. Remote connection works well, and you could try Virtual PC for your test network. b) Find the variable $OUGang in my script(s); then amend its value to reflect your domain and your Organizational Unit. You many need a little extra work with Active Directory Users and Computers in creating an OU and a handful of users. c) This script represents a learning progression, and it's also useful in troubleshooting. However, you need to manually a few users to the 'Bakers' group, other wise the script won't return any values. # PowerShell script to list users in a group $OuGang = "OU=GuysPeople,DC=cp5,DC=mosel" Note 1: This script relies on the group called 'Bakers' having members. On this occasion, it would be best to add the users manually in Active Directory Users and Computer. The other benefit is that you can use the GUI to check the tabs and double check that the script is working properly. Example 4: How To Add Users to a Named Group (Bakers)While there is a QAD cmdlet to create a group, however, I am going to concentrate on adding users to an existing group called 'Bakers'. Therefore, action point - create a group called 'Bakers', else modify my script. # PowerShell script add users to a group $OuGang = "OU=GuysPeople,DC=cp5,DC=mosel" Note 1: You did change the value of $OuGang - didn't you? Also Remember that these QAD cmdlets don't exist in the initial PowerShell install, they are only available after you successfully run: add-PSSnapin quest.activeroles.admanagement. If your script does not work refer back to the pre-requisites. Note 2: This is how the script works. $Target obtains a stream of users from the named Organizational Unit. Foreach introduces a loop. Focus on the parameters -identity and -member. $Person.dn is responsible for adding each user in the stream to the 'Bakers' group.
Guy Recommends: SolarWinds LANSurveyor
|
||||||
Download my ebook:
|
*
|
|
|
|
Home Copyright © 1999-2009 Computer Performance LTD All rights reserved Please report a broken link, or an error. | |