I have a large batch of groups that I would like to create and then add the users to them, all in the 1 script.
I have a CSV that contains the groups email, name, and a unc path to another CSV that has the unique user list for that group.
I can easily run two different scripts, one to create the groups and then another to go to each group and add the users. However, I would like to know if there is a way to achieve this in a single script. When I try to do this, the script execution ends after the first GAM command completes (which is creating the group) and will not move on to the next GAM command to add the users. I am executing the scripts in Power Shell, since it is what I am familiar with. I am pretty novice at scripting, so if I am trying to do something or missing something dumb and obvious, just tell me. Below is my code.
(Single Script to create the groups - Works just fine!)
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
$groupinfo = Import-csv "C:\GAM\Scripts\Groups Script\Groups List.csv"
foreach ($groupentry in $groupinfo)
{
}
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
(Single script to add the users - Works just fine!)
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
$groupinfo = Import-csv "C:\GAM\Scripts\Groups Script\Groups List.csv"
foreach ($groupentry in $groupinfo)
{$userslist = import-csv $($groupentry.usersfile)
foreach ($userentry in $userslist)
{
c:\gam\gam.exe update group $($groupentry.email) add member $($userentry.users)
}
}
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
(My attempt at combining them. When I run, it works up to creating the group, and then spits the rest out in plain text without any error)
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
$groupinfo = Import-csv "C:\GAM\Scripts\Groups Script\Groups List.csv"
foreach ($groupentry in $groupinfo)
{
{$userslist = import-csv $($groupentry.usersfile)
foreach ($userentry in $userslist)
{
c:\gam\gam.exe update group $($groupentry.email) add member $($userentry.users)
}
}
}
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>