CSV import via Powershell

525 views
Skip to first unread message

Josh Ferren

unread,
Oct 18, 2013, 8:30:04 AM10/18/13
to google-ap...@googlegroups.com
I am in need of some much appreciated help.  I'm running my script in Powershell and it runs find but it can't find my CSV. The CSV file is located in my GAM folder.  Does the CSV need to be placed in the same folder as my script? Also can somebody confirm that my script is correct.  I haven't tried it yet but I think I may need to make single quotes around each entry rather than the whole.

$list = Import-Csv C:\GAM\file.csv
foreach ($entry in $list)
  {
    C:\gam\gam.exe create user "$entry.username firstname $entry.firstname lastname $entry.lastname alias $entry.alias $entry.password password" suspended off changepassword on org my_org
  }

Dan Westby

unread,
Oct 18, 2013, 8:45:49 AM10/18/13
to google-ap...@googlegroups.com
The script will import the file, but you can actually put it wherever you want.  Just specify the full path.  I put my csv's in a subfolder.
As far as the script, you don't need quotes, but just change it to the following format:

C:\gam\gam.exe create user $($entry.username) firstname $($entry.firstname) lastname $($entry.lastname) alias $($entry.alias) password $($entry.password)

If you're creating a user you don't need to set suspended off since they are new.  Not sure about the change password feature or the ability to update them on an org. I have another part of the script that updates the org and places the user as well as turning off webclips.

-Dan



--
You received this message because you are subscribed to the Google Groups "Google Apps Manager" 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 http://groups.google.com/group/google-apps-manager.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-manager/fea40bff-addd-4c00-8e6f-54eef66abc2c%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Josh Ferren

unread,
Oct 18, 2013, 8:52:17 AM10/18/13
to google-ap...@googlegroups.com
If I use this format C:\gam\gam.exe create user $($entry.username) firstname $($entry.firstname) lastname $($entry.lastname) alias $($entry.alias) password $($entry.password) then the script does not run.  It just gives me the following.

Usage: gam [OPTIONS]...

Dito GAM. Retrieve or set Google Apps domain,
user, group and alias settings. Exhaustive list of com

Examples:
gam info domain
gam create user jsmith firstname John lastname Smith p
gam update user jsmith suspended on
gam.exe update group announcements add member jsmith

On Friday, October 18, 2013 8:45:49 AM UTC-4, rdaledan wrote:
The script will import the file, but you can actually put it wherever you want.  Just specify the full path.  I put my csv's in a subfolder.
As far as the script, you don't need quotes, but just change it to the following format:


If you're creating a user you don't need to set suspended off since they are new.  Not sure about the change password feature or the ability to update them on an org. I have another part of the script that updates the org and places the user as well as turning off webclips.

-Dan



On Fri, Oct 18, 2013 at 7:30 AM, Josh Ferren <josh....@pierpont.edu> wrote:
I am in need of some much appreciated help.  I'm running my script in Powershell and it runs find but it can't find my CSV. The CSV file is located in my GAM folder.  Does the CSV need to be placed in the same folder as my script? Also can somebody confirm that my script is correct.  I haven't tried it yet but I think I may need to make single quotes around each entry rather than the whole.

$list = Import-Csv C:\GAM\file.csv
foreach ($entry in $list)
  {
    C:\gam\gam.exe create user "$entry.username firstname $entry.firstname lastname $entry.lastname alias $entry.alias $entry.password password" suspended off changepassword on org my_org
  }

--
You received this message because you are subscribed to the Google Groups "Google Apps Manager" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-manager+unsub...@googlegroups.com.

Dan Westby

unread,
Oct 18, 2013, 8:57:41 AM10/18/13
to google-ap...@googlegroups.com
Make sure the fields you have in your csv match the names directly after the $entry.  Maybe you can put an example of what your csv looks like?  Double check the password as well...I think it has to match google's requirements to work.  Try replacing "password $($entry.password)" with "password q1w2e3r4" to rule that out.


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 http://groups.google.com/group/google-apps-manager.

Josh Ferren

unread,
Oct 18, 2013, 8:59:11 AM10/18/13
to google-ap...@googlegroups.com
If I run it with my original script I get Error 404: Resource Not Found: for the username, firstname, lastname, alias, and password.

Josh Ferren

unread,
Oct 18, 2013, 9:14:49 AM10/18/13
to google-ap...@googlegroups.com
Here is an example of my CSV after I took out the password entry. I replaced "password $($entry.password)" with the password we use in Google. Without the single quotes in my code then it won't even run it will give me the GAM examples. I have no idea as to why that is. 
username firstname lastname alias
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-manager+unsubscribe...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Google Apps Manager" 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.
Visit this group at http://groups.google.com/group/google-apps-manager.

Dan Westby

unread,
Oct 18, 2013, 9:21:53 AM10/18/13
to google-ap...@googlegroups.com
You didn't have to take out the actual field in your csv...powershell imports the csv into memory but the code only calls the data from fields requested and the other fields in the csv are ignored.
First try running a command manually to make sure it works, then work your way up to the script starting with a simple command including username, firstname, lastname and password, then add more and more into it. 
It appears that there is something very simple missing.  You don't need single quotes around any part of your gam command. 


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 http://groups.google.com/group/google-apps-manager.

Josh Ferren

unread,
Oct 18, 2013, 9:49:25 AM10/18/13
to google-ap...@googlegroups.com
I figured it out. GAM doesn't want to create an alias at the point of creation. I deleted the $($entry.alias) and the script worked. Been banging my head off the wall on this script since Friday. Thanks for the help. 

--
You received this message because you are subscribed to the Google Groups "Google Apps Manager" 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.
Visit this group at http://groups.google.com/group/google-apps-manager.

Dan Westby

unread,
Oct 18, 2013, 9:50:53 AM10/18/13
to google-ap...@googlegroups.com
I would suggest looking at the gam wiki page for the commands.  I never remember them off the top of my head, but if I'm going to create users, I have 3 different commands that run off the same imported csv in the same script.


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 http://groups.google.com/group/google-apps-manager.
Reply all
Reply to author
Forward
0 new messages