powershell - Start-Job scriptblock passing of variable -


i got powershell script starts script , passes parameters it. start-job not want wait until second script finished:

scripta:

start-job -name enableautounlock -scriptblock {invoke-command -script { c:\windows\system32\windowspowershell\v1.0\powershell.exe "\\path\to\script\enableautounlock.ps1" $volumedriveletter }} 

scriptb:

    [cmdletbinding()] param (     [parameter(position=0)]     [string]$drive ) <do stuff $drive here> 

$volumedriveletter drive letter gets processed i.e. "c:"

unfortunately passing of parameter variable not work although $volumedriveletter has expected value typing work correctly.

works:

start-job -name enableautounlock -scriptblock {invoke-command -script { c:\windows\system32\windowspowershell\v1.0\powershell.exe "\\path\to\script\enableautounlock.ps1" c: }} 

does not work

$volumedriveletter = "c:"  start-job -name enableautounlock -scriptblock {invoke-command -script { c:\windows\system32\windowspowershell\v1.0\powershell.exe "\\path\to\script\enableautounlock.ps1" $volumedriveletter }} 

edit: scriptb outputs passed variable empty

what missing passing of variable work?

you can use using prefix access value within scriptblock:

$volumedriveletter = "c:"  start-job -name enableautounlock -scriptblock {invoke-command -script { c:\windows\system32\windowspowershell\v1.0\powershell.exe "\\path\to\script\enableautounlock.ps1" $using:volumedriveletter }} 

or use -argumentlist parameter , pass parameter scriptblock:

start-job -name enableautounlock -scriptblock {      param($volumedriveletter)      write-host $volumedriveletter  } -argumentlist $volumedriveletter 

Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -