Search code examples
powershellgoogle-workspace

Powershell script for GAM


So I'm making a script for creating new users which includes G Suite. I'm wanting to use gam to do this. I am authorized for running gam commands and it does appear to work when I run them manually. However, it appears that when doing it in a script, I'm having authentication issues. I get an error 400: invalid password. At first I thought it was an invalid one for the create user command, but after some troubleshooting, it appears to be more so that I am not authenticated to google. Anyone have any ideas???

$firstname = Read-Host -Prompt 'Input first name'
$lastname = Read-Host -Prompt 'Input last name'
$username = $firstname.ToLower()+"."+$lastname.ToLower()
$email = $username+'@archiactvr.com'
$recovery = Read-Host -Prompt 'What is the recovery email address'


gam create user $email firstname $firstname lastname $lastname changepassword on sha recoveryemail $recovery
gam update group vancouverstudio@archiactvr.com add member user $email

Solution

  • The org is apparently required. Missed that! adding org / fixed it. Also removed the sha since I'm not passing a password through.

    gam create user $email firstname $firstname lastname $lastname changepassword on org / recoveryemail $recovery