Add2Group.ps1

This script will read an input file with users and add them to an Active Directory group. Every user needs to be on a separate line.

Commandline : ./Add2Group.ps1
#***************************************************************************
#** Script: Add2Group.ps1
#** Version: 1.0
#** Created: 10:45 17-8-2014
#** Author: Adriaan Westra
#** Website: http://www.westphil.nl
#**
#** Purpose / Comments:
#** Add users to an AD group from text file
#**
#**
#** Changelog :
#** 10:45 17-8-2014 : Initial version
#**
#***************************************************************************
#***************************************************************************
#** Start of script
#***************************************************************************
#** Clear the screen
Clear-host
#** Don’t show errors
$ErrorActionPreference = “silentlycontinue”
#** RSAT for windows needs to be installed to use the AD module
Import-Module ActiveDirectory
#** get start directory of script
$scriptdir = split-path $MyInvocation.invocationname
#** AD group name
$ADGroup = “Finance users”
#** file with users 2 add
$InputFile = “$scriptdir\users.txt”
#** Read the inputfile
$text = get-content $InputFile
#** loop through the contents of the file
ForEach( $user in $text) {
write-host “Adding $user to $ADGroup … ”
#** add the user to the group
Add-ADGroupMember -Identity $ADGroup -Member $user
}

Output :

Adding Janssen to Finance users …
Adding Smit to Finance users …

Geef een reactie

Je e-mailadres wordt niet gepubliceerd. Vereiste velden zijn gemarkeerd met *