0

I am using a command line tool called GAMADV-XTD3 to automate a lot of things on my google workspace instance such as email signatures, google drive permissions - etc.

Recently I was asked to also set out of office messages for people that email our HR department with the days that they will be out. I wrote a simple powershell script to input the email address of the user, the start date of their vacation and the end date of their vacation. Using variables I was able to create the string needed for GAM to set the out of office auto reply - but I need to manually copy and paste the command for it to run - is there a way i can pipe out the write-output into running the command it's meant for?

$email = Read-Host -Prompt "enter email"
$startdate = Read-Host -Prompt "enter startdate"
$enddate = Read-Host -Prompt "enter enddate" 
Write-Host "gam user $email vacation on subject "`"Out of Office from 
$startdate - $enddate`"" message "`"Out of the office from $startdate 
to $enddate. If there are any issues or emergencies that you need 
addressed in my absence please contact my manager `"" html startdate 
$startdate enddate $enddate"

Here is the script I am currently using. As I said - the output is correct in terms of what I need to send as a command - but it currently requires me to copy the output and enter in the command - how can i automate this last step ( push the command that i got out of write-host)

Mofi
  • 46,139
  • 17
  • 80
  • 143
  • 2
    Why not just remove `Write-Host` and the surrounding quotes? Isn't `gam` an executable? – Mathias R. Jessen Jun 27 '23 at 21:52
  • Yes, Gam is an executable. I have tried without the quotes as well, but as far as I know - Write-Host just displays the string. So removing the quotes does show the command I need - but I am trying to get that command to run instead of just displaying. – Latif Bouzoubaa Jun 27 '23 at 22:00
  • 1
    So remove `Write-Host` from the source code too. `gam user $email vacation on subject "Out of Office ..." ...` - that way PowerShell will run `gam` instead of running `Write-Host` – Mathias R. Jessen Jun 27 '23 at 22:01
  • 1
    that did the trick @MathiasR.Jessen, i don't know why I assumed i needed to write out the string then execute instead of just executing after the variables were given data. Cheers. – Latif Bouzoubaa Jun 27 '23 at 22:03
  • There is more than one type of cmdlet output : https://learn.microsoft.com/en-us/powershell/scripting/developer/cmdlet/types-of-cmdlet-output?view=powershell-7.3 – jdweng Jun 27 '23 at 23:26

0 Answers0