best business builder

Adding Hostnames to Security Groups

Adding multiple users to a Security Group can be tedious if done individually. Here is a PowerShell script that will improve efficiency when adding computer hostnames to the member section of a security group. Enjoy!!

Import-module ActiveDirectory
#Imports ActiveDirectory

$ComputerFile = Import-CSV "C:\users\username\Documents\computerfile.csv"
#This points to csv file
#####################
#EXAMPLE:
#Hostname
#Computer1
#Computer2
#####################

$GroupName = Read-Host -Prompt 'Type the Security Group Name and press Enter'
#Type the Security Group you want to add members to
#EXAMPLE:
#Property Group

$ComputerFile | ForEach-Object {
    Add-ADGroupMember -identity $GroupName -Member (Get-ADComputer -identity $_.Hostname)
}
#This adds each computer in the CSV to the Security Group Specified by the user
customer relationships

Leave a Reply

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