Skip to content
Active Directory PowerShell Script to Add Computers To AD Group

Active Directory PowerShell Script to Add Computers To AD Group

Written By Anoop C Nair
Last Updated July 26, 2024
Posted In Active Directory
SHARE

Active Directory PowerShell Script to Add Computers To AD Group. One of my friends helped me get a PowerShell script that will help Add Computer Accounts To A Security Group.

I thought of sharing the same so that it would be helpful to somebody.

Index
Active Directory PowerShell Script to Add Computers To AD Group
Active Directory PowerShell Script to Add Computers To AD Group – Table 1

Active Directory PowerShell Script to Add Computers To AD Group

This will work only on Windows 2008 R2 Domain Controllers.

Active Directory PowerShell Script to Add Computers To AD Group - Fig.1
Active Directory PowerShell Script to Add Computers To AD Group – Fig.1

The LISTOFCOMPUTERS.txt file is the input file, and it should contain a list of computers (hostnames), as shown in the screenshot below.

Patch My PC

Replace the GROUPNAME with the actual group name which you want to use.

Download the script from – TechNet Gallery

Active Directory PowerShell Script to Add Computers To AD Group - Fig.2
Active Directory PowerShell Script to Add Computers To AD Group – Fig.2

The output will be as shown below.

Active Directory PowerShell Script to Add Computers To AD Group - Fig.3
Active Directory PowerShell Script to Add Computers To AD Group – Fig.3

We are on WhatsApp. To get the latest step-by-step guides and news updates, Join our Channel. Click here –HTMD WhatsApp.

Author

Anoop C Nair has been Microsoft MVP from 2015 onwards for 10 consecutive years! He is a Workplace Solution Architect with more than 22+ years of experience in Workplace technologies. He is also a Blogger, Speaker, and leader of the Local User Group Community. His main focus is on Device Management technologies like SCCM and Intune. He writes about technologies like Intune, SCCM, Windows, Cloud PC, Windows, Entra, Microsoft Security, Career, etc.

Written by

Anoop C Nair is Workplace Technology solution architect with 25+ years of experience in global enterprise organizations such as JP Morgan, Capgemini, etc. Microsoft Certified Trainer. Microsoft MVP from 2015 onwards for consecutive 11+ years! He also conducts Intune and modern workplace tech training for enterprise organizations. He is Blogger, Speaker, and Founder of HTMD Community and HTMD Conference. His main focus is on Device Management technologies like Intune, Windows, Cloud PC. He writes about technologies like Intune, SCCM, Windows, Cloud PC, Windows, Entra, Microsoft Security.

Discussion · 4 comments

  1. I recieve a cannot validate argument error!! Are you missing a parameter is your script?

    Add-ADPrincipalGroupMembership : Cannot validate argument on parameter ‘Identity’. The argument is null. Supply a non-null argument and try the command again.
    At I:\Office365\Scripts\bldg500 computers1.ps1:10 char:31
    + Add-ADPrincipalGroupMembership <<<< $b tjxg-laptop-computers-bldg-500c
    + CategoryInfo : InvalidData: (:) [Add-ADPrincipalGroupMembership], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.ActiveDirectory.Management.Commands.AddADPrincipalGroupMembership

  2. $Computers = Get-Content -Path ‘C:\list.txt’
    foreach ($computer in $computers)
    {$dns=get-adcomputer $computer
    $b=$dns.distinguishedname
    Add-ADPrincipalGroupMembership $b ‘GROUPNAME’
    }

Join the discussion

Your email address will not be published. Required fields are marked *