-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Description
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 6Expected 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.