Passing Powershell variables to GAM - Does GAM hate $null?

360 views
Skip to first unread message

Phatmandrake

unread,
Jul 7, 2017, 12:15:22 PM7/7/17
to GAM for G Suite
I have a powershell script that accepts Params() and then inserts those variables in a gam argument.

If I'm using (signature replace "<tag> "<string>"), and string = $null, then gam will then error saying that random parts of the sentence are not valid gam commands. Putting quotes around various variables will change what Powershell spits back as being not a valid GAM command so it leads me to believe that gam can not in fact receive $null from Powershell.

Oddly, if I use a CSV GAM seems to accept empty strings just fine. It's only when I try to insert Powershell $variables in to a gam argument that I see issues. It seems okay with empty variables outside of using signature replace though. Powershell ISE seems to be recognziing replace as a reserved word of some sort.


tl;dr

Variables from param() will make gam return errors if those variables are empty and being used for for <strings> in (signature replace "<tag>" "<string>").

Ross Scroggs

unread,
Jul 7, 2017, 12:29:03 PM7/7/17
to google-ap...@googlegroups.com
Phatmandrake,

This will work in PowerShell: gam user test...@domain.com signature "Test sig with {tag}" replace "tag" '"<string>"'
The replacement string is single quote double quote string double quote single quote
This will work when string is $null

Ross

--
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/cb477768-ab69-4bb1-8482-549d988940a5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Ross Scroggs

unread,
Jul 7, 2017, 12:44:59 PM7/7/17
to google-ap...@googlegroups.com
Phatmandrake,

I may have been too quick.
This works: gam user test...@domain.com signature "Test sig with {tag}" replace "tag" '""' (single double double single)
This replaces tag with the literal $null: gam user test...@domain.com signature "Test sig with {tag}" replace "tag" '"$null"' (single double $null double single)
This replaces tag with the literal '' (two single quotes): gam user test...@domain.com signature "Test sig with {tag}" replace "tag" "'$null'"  (double single $null single double)

Three double quotes seems to be the answer: gam user test...@domain.com signature "Test sig with {tag}" replace "tag" """$null""" (double double double $null double double double)

Ross

On Fri, Jul 7, 2017 at 9:28 AM, Ross Scroggs <ross.s...@gmail.com> wrote:
Phatmandrake,

This will work in PowerShell: gam user test...@domain.com signature "Test sig with {tag}" replace "tag" '"<string>"'
The replacement string is single quote double quote string double quote single quote
This will work when string is $null

Ross
On Fri, Jul 7, 2017 at 9:15 AM, Phatmandrake <phat...@gmail.com> wrote:
I have a powershell script that accepts Params() and then inserts those variables in a gam argument.

If I'm using (signature replace "<tag> "<string>"), and string = $null, then gam will then error saying that random parts of the sentence are not valid gam commands. Putting quotes around various variables will change what Powershell spits back as being not a valid GAM command so it leads me to believe that gam can not in fact receive $null from Powershell.

Oddly, if I use a CSV GAM seems to accept empty strings just fine. It's only when I try to insert Powershell $variables in to a gam argument that I see issues. It seems okay with empty variables outside of using signature replace though. Powershell ISE seems to be recognziing replace as a reserved word of some sort.


tl;dr

Variables from param() will make gam return errors if those variables are empty and being used for for <strings> in (signature replace "<tag>" "<string>").

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



--



--

Phatmandrake

unread,
Jul 7, 2017, 11:15:00 PM7/7/17
to GAM for G Suite
So I have my script enabled so that if no parameter is specified it defaults to nothing. When I surround the variables being replaced  in triple quotes it works even in my html signature in case anyone was wondering that who stumbles across the same issue.

Param([string]$displayName = "")

signature <path> html replace "Display Name" """$displayName"""

works

On Friday, July 7, 2017 at 11:44:59 AM UTC-5, Ross Scroggs wrote:
Phatmandrake,

I may have been too quick.
This works: gam user test...@domain.com signature "Test sig with {tag}" replace "tag" '""' (single double double single)
This replaces tag with the literal $null: gam user test...@domain.com signature "Test sig with {tag}" replace "tag" '"$null"' (single double $null double single)
This replaces tag with the literal '' (two single quotes): gam user test...@domain.com signature "Test sig with {tag}" replace "tag" "'$null'"  (double single $null single double)

Three double quotes seems to be the answer: gam user test...@domain.com signature "Test sig with {tag}" replace "tag" """$null""" (double double double $null double double double)

Ross
On Fri, Jul 7, 2017 at 9:28 AM, Ross Scroggs <ross.s...@gmail.com> wrote:
Phatmandrake,

This will work in PowerShell: gam user test...@domain.com signature "Test sig with {tag}" replace "tag" '"<string>"'
The replacement string is single quote double quote string double quote single quote
This will work when string is $null

Ross
On Fri, Jul 7, 2017 at 9:15 AM, Phatmandrake <phat...@gmail.com> wrote:
I have a powershell script that accepts Params() and then inserts those variables in a gam argument.

If I'm using (signature replace "<tag> "<string>"), and string = $null, then gam will then error saying that random parts of the sentence are not valid gam commands. Putting quotes around various variables will change what Powershell spits back as being not a valid GAM command so it leads me to believe that gam can not in fact receive $null from Powershell.

Oddly, if I use a CSV GAM seems to accept empty strings just fine. It's only when I try to insert Powershell $variables in to a gam argument that I see issues. It seems okay with empty variables outside of using signature replace though. Powershell ISE seems to be recognziing replace as a reserved word of some sort.


tl;dr

Variables from param() will make gam return errors if those variables are empty and being used for for <strings> in (signature replace "<tag>" "<string>").

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



--



--
Reply all
Reply to author
Forward
0 new messages