Quantcast
Channel: SAPIEN Forums
Viewing all articles
Browse latest Browse all 504

PowerShell • trouble with start-job and passing variables to remote server

$
0
0
trying to learn my way through preventing a looping sub-command not locking up the GUI while pulling selection from a listbox (overall script it for retrieving Citrix registration status of a virtual workstation from remote server) .
found that the '$using' syntax makes a variable available inside the scriptblock for Invoke-Command
i have it working fine with the following when the variable is hard coded in line 1, i get the results locally as expected and the GUI stays responsive. removed the loop statement for simplicity

Code:

$listbox1_SelectedIndexChanged = {
$workstationsreal = "hostname"
$job = Start-Job -ScriptBlock {
Invoke-Command -computer ###### -ScriptBlock { Get-BrokerMachine -AdminAddress ##### -MaxRecordCount 2000 | ?{ $_.PublishedName -eq "$Using:workstationsreal" } }
}
$job | wait-job | receive-job -outvariable status
write-host $status.registrationstate
Write-Host $workstationsreal
however, the results are lost when i use the listbox selection instead.

Code:

$listbox1_SelectedIndexChanged = {
$workstationsreal = $listbox1.SelectedItem
$job = Start-Job -ScriptBlock {
Invoke-Command -computer ###### -ScriptBlock { Get-BrokerMachine -AdminAddress ##### -MaxRecordCount 2000 | ?{ $_.PublishedName -eq "$Using:workstationsreal" } }
}
$job | wait-job | receive-job -outvariable status
write-host $status.registrationstate
Write-Host $workstationsreal
am i missing something obvious in that $listbox1.SelectedItem gets lost where a string does not?

thanks for any insight

Statistics: Posted by monderick — Fri Jan 05, 2024 11:44 am



Viewing all articles
Browse latest Browse all 504

Trending Articles