The parameter to .AddScript() is a string, not a scriptblock, so any file position information that might have been present in the ScriptBlock object never makes it into that method. Is there some other way to get a PowerShell object to invoke a ScriptBlock without losing file position information?
Steps to reproduce
try {
[powershell]::Create().AddScript({
throw 'message'
}).Invoke()
}
catch {
$_.Exception.InnerException.ErrorRecord.ScriptStackTrace
}
Expected behavior
at <ScriptBlock>, <C:\Users\UserName\Desktop\test.ps1>: line 3
Actual behavior
at <ScriptBlock>, <No file>: line 2
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
The parameter to
.AddScript()is a string, not a scriptblock, so any file position information that might have been present in theScriptBlockobject never makes it into that method. Is there some other way to get aPowerShellobject to invoke aScriptBlockwithout losing file position information?Steps to reproduce
Expected behavior
Actual behavior
Environment data