In ps2.0, the button can directly call the variables defined in the checkbox, as follows:
$ Checkbox#checkedchanged = {
# Todo: Place custom script here
If ($ checkbox1.checked) {$ A = 1}
Else {$ A = 0}
}
$ Button#click = {
# Todo: Place custom script here
Write-host $
}
When checkbox1 is selected, after you click the button1 button, $ A returns 1; When checkbox1 is not selected, after you click the button1 button, $ A returns 0
However, in ps3.0 and 4.0, no matter whether checkbox1 is selected or not, after you click the button1 button, $ A does not return a value. In other words, you cannot directly call the variables defined in the checkbox.
The solution is to define global variables as follows:
$ Global: a = 0
$ Checkbox#checkedchanged = {
# Todo: Place custom script here
If ($ checkbox1.checked) {$ Global: a = 1}
Else {$ Global: a = 0}
}
$ Button#click = {
# Todo: Place custom script here
Write-host $ Global: A # Write-host $ A has the same effect, as long as it is defined as a global variable under checkbox1.
}
When checkbox1 is selected, after you click the button1 button, $ A returns 1; When checkbox1 is not selected, after you click the button1 button, $ A returns 0