Variable Scope within a Start-Job InitializationScript
i have following script:
$rootpath = "e:\snapshot\ggid\" $x = @("arg0", "arg1", "arg2", "arg3"); start-job -initializationscript {import-module -name "$rootpath\supportingfunctions.ps1"} -scriptblock {bcpout $args[0] $args[1] $args[2] $args[3]} -argumentlist $x
problem import-module -name not resolve $rootpath. know scoping issue. have tried using $global:, doesn't work either. how can variable resolve in scope?
john_t
i don't believe start-job has parameter passing input object initialization script, best bet drop path $env temporarily (it won't stick around when powershell session over, clean after using remove-item if prefer).
$env:myrootpath = "e:\snapshot\ggid\" $x = @("arg0", "arg1", "arg2", "arg3"); start-job -initializationscript {import-module -name "$env:myrootpath\supportingfunctions.ps1"} -scriptblock {bcpout $args[0] $args[1] $args[2] $args[3]} -argumentlist $x # if want clean afterward, remove-item env:\myrootpath
Windows Server > Windows PowerShell
Comments
Post a Comment