Currently, I am struggling to run a powershell script within another powershell GUI. I am trying to program it so that once a button is pressed, another powershell script would begin to run. The issue is that the second powershell script being ran does not run correctly when called. (It runs perfectly fine on its own.)
Code for the button:
$handler_runBTN_Click =
{
if($compliance){#runs Compliance training scripts
.\"Follow-up Email Generator.ps1"
}
}
$runBTN.Text = "Run"
$System_Drawing_Point.X = 140
$System_Drawing_Point.Y = 170
$runBTN.Location = $System_Drawing_Point
$runBTN.add_Click($handler_runBTN_Click)
$runBTN.FlatStyle = "Standard"
$emailForm.Controls.Add($runBTN)
Code not running properly when being called by button (It is called by other code but that runs correctly):
function csvCheck($intervalDate, $reminderDate) { #gathers all courses due on a specific date for a user through a csv file
for ($j = 0; $j -lt $row_count.Count; $j++) {#goes through every row of CSV file
if ($global:skip -eq $j ) {continue} #if the emails under $j are in the array $skip, the loop will skip it and continue
$requiredDate = $file[$j].'Required Date'
if (($requiredDate -eq $reminderDate)) { #courses that are coming due
$global:skip += $j #skips the iteration so it does not occur again
$bodyText = "<li>" + $file[$j].'Curriculum #' + "- <strong>Due: " + $file[$j].'Required Date' + " </strong></li>"
for ($k = $j + 1; $k -lt $row_count.Count; $k++) { #checks every other date for roccurances
if ($file[$j].'Employee ID' -eq $file[$k].'Employee ID' -and $file[$j].'Required Date' -eq $file[$k].'Required Date') {
#checks for any other courses for the same user due on the same id
$file[$k].'Last Sent' = $today
$bodyText += "<li>" + $file[$k].'Curriculum #' + "- <strong>Due: " + $file[$k].'Required Date' + " </strong></li>" #Adds onto the default bullet form text
$global:skip += $k
}
}
email $bodyText "due in $intervalDate day(s):" "comingDue"
}
}
}
I was wondering if it was my code that was causing this to happen or if it had something to do with the nature of the button.
Thanks,