Question:
I’d like to setup a cmdlet to start and stop mysql, and I’m trying to do so with Start-Job. the I’ve got the following in my Powershell profile:
1 2 3 4 5 6 |
$mysqlpath = "C:\Program Files\MySQL\MySQL Server 5.5\bin" Function Start-Mysql { Start-Job -ScriptBlock { & "$mysqlpath\mysqld.exe" } } |
The variable doesn’t seem to be expanding in the job command however? I must be missing some sort of scoping rule. Could someone please advise? Thanks!
Answer:
you have to use the -argumentlist
parameter see get-help start-job :
1 2 |
start-job -ScriptBlock { & $args[0] } -ArgumentList @($mysqlpath ) |
note that in V3 you just have to use the prefix
using:
before your varname ex:
1 2 |
Start-Job -ScriptBlock { & "$using:mysqlpath\mysqld.exe" } |