Hi,
I have a Powershell form with a button and a checkbox next to it. When I press the button, it should run a PS job.
That works fine.
However, when I select the checbkox, it should run a different command, that does not work because it does not recognize the checbox being selected.
So this is the code
if ($using:checkbox.Checked) { rest of the command ...}
else { }
Everything works fine BUT the if (checkbox.checked) ...
Tried also with giving it as $arg[0] but that doesn't work either.
Thanks for your input.
S.
if ($using:Selectbox.checked) in PS job not working as expected
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: if ($using:Selectbox.checked) in PS job not working as expected
You are not able to access the controls from the Job because it is in a different runspace / thread. I recommend passing the Checked boolean value to the job as a parameter.
David
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
Re: if ($using:Selectbox.checked) in PS job not working as expected
Thanks. You mean this then?
if ($Args[0]) { rest of the command ...}
else { }
-ArgumentList $checkbox.Checked
or ($args[0] -eq $true)
Couldn't make that one work.
if ($Args[0]) { rest of the command ...}
else { }
-ArgumentList $checkbox.Checked
or ($args[0] -eq $true)
Couldn't make that one work.
Re: if ($using:Selectbox.checked) in PS job not working as expected
Are you using the Job Tracker control set? Just update the parameters in the job scriptblock:
- -JobScript {
- #--------------------------------------------------
- #TODO: Set a script block
- #Important: Do not access form controls from this script block.
- Param([bool]$Checked)#Pass any arguments using the ArgumentList parameter
- if($Checked -eq $true) { ... }
- #--------------------------------------------------
- }
David
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
Re: if ($using:Selectbox.checked) in PS job not working as expected
Ok, thanks.
Couldn't make that one work either. Let me copy paste full code, just to be sure.
So I added
$Checked = $checkboxComputerNetWorkScan.Checked
...
-JobScript {
. $args[0]
Param ([bool]$checkboxComputerNetWorkScan.Checked)
...
-ArgumentList $ScriptPathNetworkScan, $Checked
Couldn't make that one work either. Let me copy paste full code, just to be sure.
So I added
$Checked = $checkboxComputerNetWorkScan.Checked
...
-JobScript {
. $args[0]
Param ([bool]$checkboxComputerNetWorkScan.Checked)
...
-ArgumentList $ScriptPathNetworkScan, $Checked
Re: if ($using:Selectbox.checked) in PS job not working as expected
Note the note in the code:
Code: Select all
#TODO: Set a script block
#Important: Do not access form controls from this script block.
Re: if ($using:Selectbox.checked) in PS job not working as expected
Thanks, I noticed that, but I do not see how I'm accessing the form directly in the scriptblock.
Before the scriptblock I set
$Checked = $checkboxComputerScan.Checked
The scriptblock itself then checks this value
-JobScript {
. $args[0]
Param ([bool]$Checked)
-ArgumentList $ScriptPathNetworkScan,$Checked
Before the scriptblock I set
$Checked = $checkboxComputerScan.Checked
The scriptblock itself then checks this value
-JobScript {
. $args[0]
Param ([bool]$Checked)
-ArgumentList $ScriptPathNetworkScan,$Checked
Re: if ($using:Selectbox.checked) in PS job not working as expected
Two arguments? Then use two parameters
Code: Select all
-ArgumentList $ScriptPathNetworkScan,$Checked
-JobScript {
Param (
$ScriptPathNetworkScan,
$Checked
)
Re: if ($using:Selectbox.checked) in PS job not working as expected
Thanks for your input, but I'm not getting fully howto pass the $Checked for $checkbox1.checked, since I should not invoke form items (?)
This is what I got, how do I check the $checkbox.checked then IN the job?
This is what I got, how do I check the $checkbox.checked then IN the job?
Code: Select all
Add-JobTracker -Name 'Get Service' `
-JobScript {
Param ([bool]$Checked)
if ($checked)
{
(Get-Service -Name AdobeARMservice).name
}
else
{
(Get-Service -Name Winmgmt).name
}
}`
-CompletedScript {
Param ($Job)
}`
-ArgumentList $Checked
}