customer relationships

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

Got a project that needs expert IT support?

From Linux and Microsoft Server to VMware, networking, and more, our team at CR Tech is here to help.

Get personalized support today and ensure your systems are running at peak performance or make sure that your project turns out to be a successful one!

CONTACT US NOW
best vpn deal