I am trying to use a variable created in an outer ForEach loop inside an inner ForEach loop. The value does not pass thru as I expect and is always null.
Notice The value for $server is always null can you tell me why and how to fix?
$Srvrs = "SVR1"; $Srvrs | ForEach-Object { $server = $_; Write-Host "Server value in outer Foreach:" $server; $sourceFilesLoc = "D:\Test\SetupSoftwareAndFiles" $sourceFiles = Get-ChildItem -LiteralPath $sourceFilesLoc; $sourceFiles | ForEach-Object { Start-Job -InputObject $server -ScriptBlock { Write-Host "Server value in inner Foreach:" $server; } } }