Equivilent to Powershell -WhatIf

301 views
Skip to first unread message

Curtis Kutzan

unread,
Jan 13, 2017, 12:51:20 PM1/13/17
to GAM for G Suite
Hi,

Apologies if this exists somewhere, I google the heck out of it...

How do people test their commands before executing? Is it even possible?  With PowerShell there is the -WhatIf command which simulates the command running but makes no changes.

I need to perform some commands that make big changes and as a new GAM user I am scared stupid to run them even though I am 99% sure they are correct.

Thanks,

Curt

Kevin Melillo

unread,
Jan 13, 2017, 1:19:02 PM1/13/17
to google-ap...@googlegroups.com
I create my scripts with an IF statement.  If the command line argument supplies is the word "doit" then it processes the command.  If not, it will just echo the results of the command back so I can review the changes that would have been made.

For example, when creating a new user in our environment, the request comes in with the email address needed, and the business unit the user is in.  The business unit determines the ORG and Groups we add the member to.
I add this information to a CSV file, and run the command 'nUser'

Here is an example of the bash script nUser

INPUT=userlist.csv
OLDIFS=$IFS
IFS=,
[ ! -f $INPUT ] && { echo "$INPUT file not found"; exit 99; }
while read userName firstName lastName orgName groupName
do
  # do some preconfiguration work, and variable setting here...
  if [ -z "$" ]
  then
    echo -e "MESSAGE OR COMMAND TO BE PROCESSED"
    echo -e "LINE 2 COMMAND"
    echo -e "LINE 3 COMMAND"
  else
    if [ "${1^^}" == "DOIT" ]
      then
        # RUN ACTUAL COMMANDS HERE
    fi
  fi
done < $INPUT
IFS=$OLDIFS

That is basically the format I use for my scripts, so I can check the output before running the script.

--
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/25bcae72-310e-480a-a559-1bc0549b1da8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Kevin Melillo
Electronic Communications Analyst
Information Technology
445 Hoes Lane
Piscataway, NJ 08854


Curtis Kutzan

unread,
Jan 13, 2017, 1:36:43 PM1/13/17
to GAM for G Suite
Thanks! That looks impressive, however I am not quite sure how I would modify it for the following command that I want to run:

gam update group classroom-teachers@<domain>.ca sync notsuspended member ou_and_children "Staff"

Kevin Melillo

unread,
Jan 13, 2017, 1:45:25 PM1/13/17
to google-ap...@googlegroups.com
Ah, you are doing a sync there which may make alot of changes.  My little script will not be able to display those changes for you before they are run.  The only thing I can suggest for that type of command is to pipe the output to a text file, and review the text file for any changes.  

Maybe pipe the output to a file as well for review.  That way you can review the results of the command, and reverse any changes that may not have been meant to be made.

--
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.

For more options, visit https://groups.google.com/d/optout.

Ross Scroggs

unread,
Jan 13, 2017, 1:54:19 PM1/13/17
to google-ap...@googlegroups.com
Curtis/Kevin,

I've thought about something like this for my advanced gam: https://github.com/taers232c/GAMADV-X
It's a good idea, but it would be a lot of code. That being said, the update group command would be fairly easy to modify.
Curtis, what other commands scare you?

One of the problems with regular Gam is its terse output, for many commands there is not enough output to accurately capture what went on.
Gamadv-x gives detailed/verbose output, you'll know what went on.

Ross

On Fri, Jan 13, 2017 at 10:45 AM, Kevin Melillo <k.me...@ieee.org> wrote:
Ah, you are doing a sync there which may make alot of changes.  My little script will not be able to display those changes for you before they are run.  The only thing I can suggest for that type of command is to pipe the output to a text file, and review the text file for any changes.  

Maybe pipe the output to a file as well for review.  That way you can review the results of the command, and reverse any changes that may not have been meant to be made.
On Fri, Jan 13, 2017 at 1:36 PM, Curtis Kutzan <curtis...@eips.ca> wrote:
Thanks! That looks impressive, however I am not quite sure how I would modify it for the following command that I want to run:

gam update group classroom-teachers@<domain>.ca sync notsuspended member ou_and_children "Staff"

On Friday, January 13, 2017 at 10:51:20 AM UTC-7, Curtis Kutzan wrote:
Hi,

Apologies if this exists somewhere, I google the heck out of it...

How do people test their commands before executing? Is it even possible?  With PowerShell there is the -WhatIf command which simulates the command running but makes no changes.

I need to perform some commands that make big changes and as a new GAM user I am scared stupid to run them even though I am 99% sure they are correct.

Thanks,

Curt

--
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+unsubscribe...@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.
--
Kevin Melillo
Electronic Communications Analyst
Information Technology
445 Hoes Lane
Piscataway, NJ 08854


--
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.

For more options, visit https://groups.google.com/d/optout.



--
Reply all
Reply to author
Forward
0 new messages