Hello!
I apologize I post a lot but I am just learning how to use the tool and have searched the forums for this issue but did not quite see what I was looking for on them.
I am attempting to use the start job button for running a backup and restore process. I read that within the script code block you use to start the job, you cannot use form controls. The start job works flawless for the backup portion but the restore portion has user input (check boxes) and without being able to insert those into the code block (if checkbox is checked run x function), what is the best way to work around this, a child form? Or is there a way to use a checkbox portion of the form within a different part of the job script? Thanks as always for your time.
JobStatus Button - Form
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Re: JobStatus Button - Form
Hello!
I do have two buttons that are start job designated, Backup and Restore. The problem I run into is with Restore it doesn't appear to be running the script when it is pressed (it doesn't perform any action and is just immediately done).
The backup code (snipped):
The restore is (snipped):
I am able to execute this code without the job parameters but when I insert it into the second job code it basically just says done right away and skips all the code and doesn't execute anything within the block.
I do have two buttons that are start job designated, Backup and Restore. The problem I run into is with Restore it doesn't appear to be running the script when it is pressed (it doesn't perform any action and is just immediately done).
The backup code (snipped):
Code: Select all
$buttonStartJob_Click={
$buttonStartJob.Enabled = $false
#Create a New Job using the Job Tracker
$paramAddJobTracker = @{
Name = 'BackupJob'
JobScript = {
#--------------------------------------------------
#TODO: Set a script block
#Important: Do not access form controls from this script block.
Param ($Argument1) #Pass any arguments using the ArgumentList parameter
for ($i = 0; $i -lt 50; $i++) { Start-Sleep -Milliseconds 100 }
##Creating Backup Folder
$FolderName = "$env:HOMESHARE\TXBackup"
Add-Type -AssemblyName PresentationFramework
if ([System.IO.Directory]::Exists($FolderName))
{
$msgBoxInput = [System.Windows.MessageBox]::Show('A current backup exists, would you like to delete the current backup? (NOTE: This action cannot be undone)', 'Confirmation', 'YesNo')
switch ($msgBoxInput)
Code: Select all
$buttonStartJob2_Click={
$buttonStartJob2.Enabled = $false
#Create a New Job using the Job Tracker
$paramAddJobTracker = @{
Name = 'RestoreJob'
JobScript = {
#--------------------------------------------------
#TODO: Set a script block
#Important: Do not access form controls from this script block.
Param ($Argument1) #Pass any arguments using the ArgumentList parameter
for ($i = 0; $i -lt 50; $i++) { Start-Sleep -Milliseconds 100 }
if ($checkboxChrome.Checked -eq $true)
{
##Restoring Chrome Bookmarks
$rbookmarks = "$env:HOMESHARE\TXBackup\Chrome\Bookmarks"
#Copy-Item $rbookmarks "$env:userprofile\Appdata\Local\Google\Chrome\User Data\Default\Bookmarks" -Recurse -Force
Copy-Item $rbookmarks "C:\Test" -Recurse -Force
}
if ($checkboxOtlksignatures.Checked -eq $true)
{
##Restoring Outlook Signatures
$rosignature = "$env:HOMESHARE\TXBackup\OutlookSignatures\*"
#Copy-Item $rosignature "$env:userprofile\Appdata\Roaming\Microsoft\Signatures\" -Recurse -Force
Copy-Item $rosignature "C:\Test" -Recurse -Force
}
if ($checkboxOffnrmdotm.Checked -eq $true)
Re: JobStatus Button - Form
Okay, that is what I was thinking. Is there some additional documentation/resources on how to manage using $Arguments to pass those? I am fairly new to Powershell and I am tasked to build a GUI at the same time so there has definitely been a learning curve
Re: JobStatus Button - Form
That constitutes multiple questions that can't be answered easily. Here is a link that will give the answers along with examples:
https://www.sapien.com/books_training/W ... werShell-4
The following may also be helpful: https://info.sapien.com/index.php/guis/ ... sive-forms
You can pass the properties of any control or group of controls in the $Arguments list.
https://www.sapien.com/books_training/W ... werShell-4
The following may also be helpful: https://info.sapien.com/index.php/guis/ ... sive-forms
You can pass the properties of any control or group of controls in the $Arguments list.