Link to home
Start Free TrialLog in
Avatar of MilesLogan
MilesLoganFlag for United States of America

asked on

Script to add users to an AD group - export file with confirmation of what accounts where added.

Hi EE

I want to use the script below to set a task to add users to a group every night . The Users.txt file will be updated
by the application owner .

can someone help me modify it so the script outputs a file of the SamAccountNames that where added ?
something like  export-csv C:\PS\AddedtoXXXgroup_$((Get-Date -Format MM-dd-yyyy)).csv -NoTypeInformation


Foreach ($User in GC \\Server\Share\Users.txt){
GC C:\PS\groups.txt | % {
Add-ADGroupmember -identity $_ -member $User
      }
}
ASKER CERTIFIED SOLUTION
Avatar of SubSun
SubSun
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MilesLogan

ASKER

Subsun .. many thanks as always ! wow
You are welcome!