I am looking for a modification to a script that I found online for google forms. The scriptt fetches the responses and puts it in to an email. We use this to let supervisors send in newly hired people. I am not able to modify the script to add a new line at the end where I can use the variables from the form to type out a powershell script automatically that we then use to create accounts in the active directory etc.
I already have the powershell script but I cant seem to get it into the google forms script.
I have tried to modify this part which I assume hold what sends the message. But I cant make it include a string at the end which I can put different variables in.
for ( var keys in columns ) {
var key = columns[keys];
if ( e.namedValues[key] && (e.namedValues[key] != "") ) {
message += key + ' :: '+ e.namedValues[key] + "\n\n";
This is the google forms code
/* Send Google Form by Email v2.1 */
/* For customization, contact the developer at amit@labnol.org */
/* Tutorial: http://www.labnol.org/?p=20884 */
function Initialize() {
var triggers = ScriptApp.getProjectTriggers();
for(var i in triggers) {
ScriptApp.deleteTrigger(triggers[i]);
}
ScriptApp.newTrigger("SendGoogleForm")
.forSpreadsheet(SpreadsheetApp.getActiveSpreadsheet())
.onFormSubmit()
.create();
}
function SendGoogleForm(e)
{
try
{
//Här fyller du i mailadresserna för resp avdelning.
var security = "";
var hr = "";
var it = "";
//Ärende på mailet
var subject = "Test";
//Slår ihop alla mailadresser till en.
var email = hr +","+ security +","+ it;
// You may replace this with another email address
//var email = Session.getActiveUser().getEmail();
var s = SpreadsheetApp.getActiveSheet();
var columns = s.getRange(1,1,1,s.getLastColumn()).getValues()[0];
var message = "";
// Only include form fields that are not blank
for ( var keys in columns ) {
var key = columns[keys];
if ( e.namedValues[key] && (e.namedValues[key] != "") ) {
message += key + ' :: '+ e.namedValues[key] + "\n\n";
}
if (key == "Förnamn")
var fornamn = e.namedValues[key];
else if (key == "Efternamn")
var efternamn = e.namedValues[key];
}
//Lägger till eventuellt namn i ämnesraden.
subject += ", " + fornamn + " " + efternamn ;
// This is the MailApp service of Google Apps Script that sends the email. You can also use GmailApp for HTML Mail.
MailApp.sendEmail(email, subject, message);
} catch (e) {
Logger.log(e.toString());
}
}
Here is the powershell code which I want to get into the message sent. Between each ' ' should a variable be fetched from the google form.
New-ADUser -SamAccountName 'fornamn.efternamn' -Name 'Förnamn Efternamn' -GivenName 'Förnamn' -Surname 'Efternamn' -Description 'Läkare' -OfficePhone '' -EmailAddress 'fornamn.efternamn@yrdy.com' -Path 'OU=Users-W10,OU=VC Hornstull,OU=Neron,DC=neron,DC=internal' -Company 1 -Department 2 -Title 3