I can't seem to use a function, or variable in the scriptblock of a Job. I understand the scope issue and that it's another process, and I think I need to pass the variables with the -argumentlist? But I can't seem to get this working. Also not when using $script:Uefi
So I actually have the following issues:
- Calling the function in a Job
- Passing variables set by e.g. a combobox to a Job to do further If-Then code
My example function:
PowerShell Code
Double-click the code block to select all.function check-uefi { if ($comboboxMediaplayerkeuze.Text -eq "MSI Windbox DC100") { $UEFI = "false" } else { $UEFI = "true" }The Start-Job using -argumentlist to pass variables
PowerShell Code
Double-click the code block to select all.#Start the Job $job = Start-Job -Name $Name -ScriptBlock $JobScript -ArgumentList $UEFI
The -scriptblock code: I was hoping $p1 would have the value of $UEFI
PowerShell Code
Double-click the code block to select all.#Create a New Job using the Job Tracker Add-JobTracker -Name "JobName" ` -JobScript { #-------------------------------------------------- Param ($p1)#Pass any arguments using the ArgumentList parameter # trying to call the check-uefi function check-uefi if ($p1 -eq "true") { $testvar = "check to see is value can be read: True" diskpart /s m:\scripts\createpartitions-uefi.txt | Out-String | Out-File x:\log.txt -Append manage-bde -on w: | Out-String | Out-File x:\log.txt -Append Expand-WindowsImage -imagePath m:\images\windows-nuc-i3.wim -ApplyPath w:\ -Index:1 | Out-String | Out-File x:\log.txt -Append } else { diskpart /s m:\scripts\createpartitions-non-uefi.txt $testvar = "check to see is value can be read: False" }