This came up when experimenting with @lzybkr's workaround for #7530. In short, I'm using the ScriptBlock (not just its string representation) from one runspace in another so that file position information is correctly reported when an error is encountered.
Steps to reproduce
$scriptblock = {
"a in dot-invoked scriptblock: $a"
}
$powershell = [powershell]::Create().
AddScript({
"a in outer scriptblock: $a"
. $args[0]
}).
AddArgument($scriptblock)
$initialSessionState = [initialsessionstate]::CreateDefault()
$initialSessionState.Variables.Add(
[System.Management.Automation.Runspaces.SessionStateVariableEntry]::new(
'a',
1,
''
)
)
$runspace = [runspacefactory]::CreateRunspace($initialSessionState)
$runspace.Open()
$powershell.Runspace = $runspace
$powershell.Invoke()
Expected behavior
a in outer scriptblock: 1
a in dot-invoked scriptblock: 1
Actual behavior
a in outer scriptblock: 1
a in dot-invoked scriptblock:
Environment data
> $PSVersionTable
Name Value
---- -----
PSVersion 6.1.0-preview.4
PSEdition Core
GitCommitId 6.1.0-preview.4
OS Microsoft Windows 6.3.9600
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
This came up when experimenting with @lzybkr's workaround for #7530. In short, I'm using the ScriptBlock (not just its string representation) from one runspace in another so that file position information is correctly reported when an error is encountered.
Steps to reproduce
Expected behavior
Actual behavior
Environment data