none
script - add member to a security group

    Question

  • We have domain controller

    DC: ADC.COM

    Security Group Name: HR

    OU: Employees

    User: Hr01, Hr02, and Hr03 

    I want to create this scenario on how to add member to security group in script and batch using the above information

    can you please help me , because I need this script in some application need to be executed


    Robert

    Thursday, December 22, 2016 4:32 AM

Answers

  • Hi,

    >>I want to create this scenario on how to add member to security group in script and batch using the above information

    You could refer to following sampes:

    Get security group:

    Get-ADGroup -Filter * -Properties * |?{.GroupCategory -eq 'Security' -and .SamAccountName -eq 'HR'}
    

    Add members to group:

    help  Add-ADGroupMember  -Examples
    

    Best regards,

    Andy


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    • Marked as answer by help.me.please Sunday, January 15, 2017 11:54 AM
    Thursday, December 22, 2016 9:09 AM
    Moderator
  • You can try below one:

    Get-ADUser -SearchBase 'OU=Employees,DC=ADC,DC=com' -Filter * | % { Add-ADGroupMember 'HR' -Members $_ -WhatIf }

     OR

    dsquery user "OU=Employees,DC=ADC,dc=com" | dsmod group "CN=HR,OU=organizationalUnitname,DC=ADC,DC=com" -addmbr

    • Marked as answer by help.me.please Sunday, January 15, 2017 11:54 AM
    Thursday, December 22, 2016 2:02 PM

All replies

  • Hi,

    >>I want to create this scenario on how to add member to security group in script and batch using the above information

    You could refer to following sampes:

    Get security group:

    Get-ADGroup -Filter * -Properties * |?{.GroupCategory -eq 'Security' -and .SamAccountName -eq 'HR'}
    

    Add members to group:

    help  Add-ADGroupMember  -Examples
    

    Best regards,

    Andy


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    • Marked as answer by help.me.please Sunday, January 15, 2017 11:54 AM
    Thursday, December 22, 2016 9:09 AM
    Moderator
  • You can try below one:

    Get-ADUser -SearchBase 'OU=Employees,DC=ADC,DC=com' -Filter * | % { Add-ADGroupMember 'HR' -Members $_ -WhatIf }

     OR

    dsquery user "OU=Employees,DC=ADC,dc=com" | dsmod group "CN=HR,OU=organizationalUnitname,DC=ADC,DC=com" -addmbr

    • Marked as answer by help.me.please Sunday, January 15, 2017 11:54 AM
    Thursday, December 22, 2016 2:02 PM