GAM Script returning Error: 404: Resource Not Found: userkey

549 views
Skip to first unread message

Nelson Louie

unread,
Jul 22, 2021, 1:41:36 PM7/22/21
to GAM for Google Workspace
Hello:

I have a script to delete photos from user email profiles and cannot see what is missing in the script:


# Prompt user for CSV file path
$filepath = Read-Host -Prompt ìEnter the path to your CSV file"

# Import the file into a variable
# Test file = test_run.csv
# Prod run = student_email_addresses.csv
$emailaddresses = Import-Csv $filepath

#  Loop through each row and process each row
foreach ($email in $emailaddresses)
† {
# this command deletes the student's google profile photo
gam user $email delete photo
# echo $email
† }


It is not clear to me why I am getting the error msg when powershell processes this GAM script.

Thanks

Ross Scroggs

unread,
Jul 22, 2021, 2:51:53 PM7/22/21
to google-ap...@googlegroups.com
nelson,

Uncomment the echo $email; what does it show?

Ross

This is a staff email account managed by St. John's School.  This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the sender.

--
You received this message because you are subscribed to the Google Groups "GAM for Google Workspace" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-man...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-manager/ec619cc2-19a2-4f17-9d5a-69bf05c2fc94n%40googlegroups.com.


--

Nelson Louie

unread,
Jul 22, 2021, 5:31:25 PM7/22/21
to GAM for Google Workspace
Hello Ross, 

Uncommenting the #echo $email will send the list of email addresses to the screen.  What would cause the gam command to be different from the echo command?

Thanks

Nelson

Ross Scroggs

unread,
Jul 22, 2021, 5:45:33 PM7/22/21
to google-ap...@googlegroups.com
Nothing, but we can see the address you're trying to use.

Ross



--

Nelson Louie

unread,
Jul 22, 2021, 7:39:40 PM7/22/21
to GAM for Google Workspace
Hello Ross,  

OK I suspect the 404 error is due to the fact that not all of the users have a photo set up, hence the delete photo is returning a 404 when the photo is non existent.  How would I set up an if then else on a 404 error when processing the user record?

Thanks

Nelson

Ross Scroggs

unread,
Jul 22, 2021, 7:59:26 PM7/22/21
to google-ap...@googlegroups.com
Nelson,

Take one of the addresses that fails and do:
gam info user us...@domain.com
gam user us...@domain.com show gmailprofile

Ross



--

Ross Scroggs

unread,
Jul 23, 2021, 8:50:29 AM7/23/21
to google-ap...@googlegroups.com
Nelson,

Do the following with any valid email address:
gam user us...@domain.com check serviceaccount

Reply all
Reply to author
Forward
0 new messages