Running GAM with Powershell pulling from AD

1,294 views
Skip to first unread message

Eric Krebill TCAS

unread,
Jul 12, 2018, 8:59:20 AM7/12/18
to GAM for G Suite
I'm storing data for my users in empty AD fields.  Previously I was exporting this data and running GAM against it, but that doesn't make sense since PowerShell can read from AD.  So I'm trying to skip a step and pull the data from AD directly and using it in GAM.  Easy, right?  Here's the script so far.

$students = Get-ADUser -filter {mail -like "*@domain.com"} -Searchbase "OU=Test,DC=DOMAIN,DC=local" -ResultSetSize $null `

foreach ($user in $students)
{
. C:\GAMADV\gam.exe update group $($user.ipPhone) add member $($user.mail)

}

Unfortunately I'm getting an error and it doesn't run.  

gam.exe : Command: C:\GAMADV\gam.exe update group add >>>member<<<
At C:\PowerShell\Students\GAM\GAM_PrintGroups_test.ps1:31 char:1
+ &C:\GAMADV\gam.exe update group $($user.ipPhone) add member $($user.m ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   
+ CategoryInfo          : NotSpecified: (Command: C:\GAM...d >>>member<<< :String) [], RemoteException
   
+ FullyQualifiedErrorId : NativeCommandError
 
ERROR
: Invalid argument
Help: Syntax in file C:\GAMADV\GamCommands.txt
Help: Documentation is at https://github.com/taers232c/GAMADV-X/wiki

Suggestions?  I'm not sure why it doesn't like "member" in this context.

Ross Scroggs

unread,
Jul 12, 2018, 9:08:44 AM7/12/18
to google-ap...@googlegroups.com
Eric,

Look at the error message: gam.exe : Command: C:\GAMADV\gam.exe update group add >>>member<<< 
Note that there is no group name between group and add, so $($user.ipPhone) was completely empty.
Note that there is nothing after member either, so $($user.mail) isn't returning anything either.

I'm not PowerShell knowledgeable so maybe someone else can point out what the variable expansion isn't working.

--
You received this message because you are subscribed to the Google Groups "GAM for G Suite" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-man...@googlegroups.com.
To post to this group, send email to google-ap...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-apps-manager.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-manager/7c0c5c12-ac0c-48ac-8b01-58b7c8008d9b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Eric Krebill TCAS

unread,
Jul 12, 2018, 1:58:49 PM7/12/18
to GAM for G Suite
Using your hint, I was able to figure out what to do.  I didn't expand the properties that I wanted from AD in the beginning.  I'm going to paste my script here in case anyone else wants to do this.

$students = Get-ADUser -filter {mail -like "*@domain.com"} -Searchbase "OU=Test,DC=domain,DC=local" -ResultSetSize $null Properties mail,ipPhone `

foreach ($user in $students)
{
& C:\GAMADV\gam.exe update group $($user.ipPhone) add member $($user.mail)
}

Reply all
Reply to author
Forward
0 new messages