I seem to have a lot of trouble understanding how to get this working. I am trying to gather all variables up front that way I can call psexec and pass those variables to it in a scriptblock.
The reason I am using psexec is due to the fact I have old 2003 servers without powershell installed. My goal was to have powershell multithread out against a list of servers in a text file and spawn processes in a manner below.
#Gather info
$servers = "test1234"
$userName = Read-host "What is the user name?"
$userPassword = Read-host "What is the user password?"
$scriptBlockwork = {c:\scripts\message\psexec.exe "$servers" -u domain\$userName -p $userPassword -c InstallMShotfix.cmd -f InstallMShotfix.cmd}.GetNewClosure()
& $scriptBlockwork
echo $scriptBlockwork
Why does the script block not take the variables defined even when using .GetNewClosure()