Add-ADGroupMember of the psad command

Source: Internet
Author: User

Add-ADGroupMember of the psad command

We created our active directory group above, but it is empty. Next we must add members to it. Otherwise, it will never work if it is always an empty group. So we need to add corresponding users. How can we add them? Fellow Me

Let's take a look at the command to be executed:

It is very simple. We only need to execute simple commands to add our users to our group. We can see the following for a single user group:

Add-adgroupmember-identity it-members lirun and lisi:

 

The above is the simplest mode. What should I do if I want to add all the users of an OU to a group? For example, we want all users under line OU to be added to linegroup:

At this time, we need to first know the users under our Line OU. What command should we use? Get-aduser: Let's Get the user out first without worrying about this command:

The next step is to add these users to the group and execute the following PS command to complete this action:

Get-aduser-searchbase "ou = line, dc = pilot, dc = com"-filter * | foreach {add-adgroupmember-identity linegroup-members $ _. name}

Next, let's take a look at something more advanced, that is, adding users to the group below OU based on different OU. At this time, there are three layers of OU users in the production line, all OU-level users of the production line need to be added to our Linegroup group.

Therefore, we need to build such a CSV file to join the corresponding group, and edit the file in the following format:

Ou, Groupname

It, itgroup

Caiwu, caiwugroup

Line, linegroup

Ad, adgroup

 

Next, we will write a script to add the corresponding OU users to our corresponding group.

$oulist=import-csv-path d:\grouplist.csvForeach($ouin $oulist){$ouname="ou="+$ou.ou+",dc=pilot,dc=com";$userinou=get-aduser-searchbase $ouname -searchscope "subtree" -filter *;Foreach($userin $userinou){Add-adgroupmember-identity $ou.groupname -members $user.name;}}

Let's take a look at the results. Except for an account that does not exist in the Active Directory, all the other accounts are added to the group below the corresponding OU:


 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.