Running GAM commands from Powershell WinForms

896 views
Skip to first unread message

Nick M.

unread,
Aug 11, 2017, 11:33:08 AM8/11/17
to GAM for G Suite
Hey Group,

I'm working on creating a single page form using powershell to create a user and assign that user to groups on our Gsuite domain using GAM.  Our usernames consist of Firstname.Lastname.  The problem is that GAM is not liking the input variables.  Here's a snippet of the code I'm working with.

Function button2_RunOnClick()
{
    pushd F:\Gam
    #gam create user $textBox1'.'$textBox2 firstname $textBox1 lastname "$textBox2" password "RunForestRun!" changepassword off
    if ($checkBox1.Checked) {gam update group test...@mydomain.edu add member user $textBox1'.'$text...@mydomain.edu}
}

If I change the variables to the username Bubba.Gump I can get it to add the group to the user.  If I leave the variables I receive the error.

gam :  adding member System.Windows.Forms.TextBox, Text: Bubba.System.Windows.Forms.TextBox, Text: Gu...@mydomain.edu...
At F:\GAM\NewEmployeeGmail1.ps1:165 char:30
+ ... 1.Checked) {gam update group test...@mydomain.edu add member u ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: ( adding member ...rcollege.edu...:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError
 
ERROR: 400: Invalid Input: memberKey - invalid

Ross Scroggs

unread,
Aug 11, 2017, 11:37:42 AM8/11/17
to google-ap...@googlegroups.com
Nick,

PowerShell is strange about quoting, try:
    if ($checkBox1.Checked) {gam update group test...@mydomain.edu add member user """$textBox1.$textBox2@mydomain.edu"""}
Triple double quotes are magic.

Ross

On Fri, Aug 11, 2017 at 8:15 AM, Nick M. <nick.m...@gmail.com> wrote:
Hey Group,

I'm working on creating a single page form using powershell to create a user and assign that user to groups on our Gsuite domain using GAM.  Our usernames consist of Firstname.Lastname.  The problem is that GAM is not liking the input variables.  Here's a snippet of the code I'm working with.

Function button2_RunOnClick()
{
    pushd F:\Gam
    #gam create user $textBox1'.'$textBox2 firstname $textBox1 lastname "$textBox2" password "RunForestRun!" changepassword off
    if ($checkBox1.Checked) {gam update group test...@mydomain.edu add member user $textBox1'.'$textBox2@mydomain.edu}

}

If I change the variables to the username Bubba.Gump I can get it to add the group to the user.  If I leave the variables I receive the error.

gam :  adding member System.Windows.Forms.TextBox, Text: Bubba.System.Windows.Forms.TextBox, Text: Gu...@mydomain.edu...
At F:\GAM\NewEmployeeGmail1.ps1:165 char:30
+ ... 1.Checked) {gam update group test...@mydomain.edu add member u ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: ( adding member ...rcollege.edu...:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError
 
ERROR: 400: Invalid Input: memberKey - invalid

--
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-manager+unsub...@googlegroups.com.
To post to this group, send email to google-apps-manager@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/554ec667-16a1-4d83-b9b2-eead1b6421d2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Nick M.

unread,
Aug 11, 2017, 11:51:36 AM8/11/17
to GAM for G Suite
Ross,

No luck.  Tried the triple double quotes and I get that same 400 error.

Nick


On Friday, August 11, 2017 at 9:37:42 AM UTC-6, Ross Scroggs wrote:
Nick,

PowerShell is strange about quoting, try:
    if ($checkBox1.Checked) {gam update group test...@mydomain.edu add member user """$textBox1.$text...@mydomain.edu"""}
Triple double quotes are magic.

Ross
On Fri, Aug 11, 2017 at 8:15 AM, Nick M. <nick.m...@gmail.com> wrote:
Hey Group,

I'm working on creating a single page form using powershell to create a user and assign that user to groups on our Gsuite domain using GAM.  Our usernames consist of Firstname.Lastname.  The problem is that GAM is not liking the input variables.  Here's a snippet of the code I'm working with.

Function button2_RunOnClick()
{
    pushd F:\Gam
    #gam create user $textBox1'.'$textBox2 firstname $textBox1 lastname "$textBox2" password "RunForestRun!" changepassword off
    if ($checkBox1.Checked) {gam update group test...@mydomain.edu add member user $textBox1'.'$text...@mydomain.edu}

}

If I change the variables to the username Bubba.Gump I can get it to add the group to the user.  If I leave the variables I receive the error.

gam :  adding member System.Windows.Forms.TextBox, Text: Bubba.System.Windows.Forms.TextBox, Text: Gu...@mydomain.edu...
At F:\GAM\NewEmployeeGmail1.ps1:165 char:30
+ ... 1.Checked) {gam update group test...@mydomain.edu add member u ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: ( adding member ...rcollege.edu...:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError
 
ERROR: 400: Invalid Input: memberKey - invalid

--
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-manager+unsub...@googlegroups.com.
To post to this group, send email to google-ap...@googlegroups.com.



--

Nick M.

unread,
Aug 11, 2017, 1:15:07 PM8/11/17
to GAM for G Suite
Worked with Ross over the phone and we figured out the issue.


Function button2_RunOnClick()
{
    pushd F:\Gam
    gam create user ($textBox1.Text+"."+$textBox2.Text+"@mydomain.edu") firstname $textBox1.text lastname "$textBox2.text" password "RunForestRun!" changepassword off
    if ($checkBox1.Checked) {gam update group test...@mydomain.edu add member user ($textBox1.Text+"."+$textBox2.Text+"@mydomain.edu")}
}

I'm still getting a generic error but everything creates. 

Thanks Ross for going the extra mile on this one! 
Reply all
Reply to author
Forward
Message has been deleted
0 new messages