Skip to content

MyInvocation.Line doesn't work for commands split across multiple lines #12609

@weshaggard

Description

@weshaggard

My team uses powershell scripts a lot as part of our Azure DevOps pipelines and there is a lot of times we don't have enough information to debug when something goes wrong so I'm been trying to find a nice easy way to output the exact command line so we can try and reproduce it locally. I found an old PS blog post https://devblogs.microsoft.com/powershell/getting-all-your-parameters/ which I thought would do the job so I started using MyInvocation.Line but the first time I needed to use this information to debug I realized it only contained the first line of the command line and since we often split long command lines across multiple lines to make reading easier that didn't end up helping like I wanted.

Steps to reproduce

> function test { $myinvocation.line.substring($myInvocation.OffSetInLine-1) }
> test 1 2 3 `
>> 4 5 6

Expected behavior

test 1 2 3 4 5 6

or perhaps

test 1 2 3 `
4 5 6

Actual behavior

test 1 2 3 `

Environment data

> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.0.0
PSEdition                      Core
GitCommitId                    7.0.0
OS                             Microsoft Windows 10.0.18363
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

I'd also be happy with another simple way to echo the exact command line of a script call.

Metadata

Metadata

Assignees

Labels

Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-FixedThe issue is fixed.WG-Enginecore PowerShell engine, interpreter, and runtime

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions