I'm using some GIT commands in my PowerShell scripts. Most of the time I'm calling the GIT commands via Invoke-Expression
so that I, e.g.
- can parse the output, or/and
- forward the out to a logging method.
At some GIT commands I recognized that not all output is returned via Invoke-Expression
though the documentation states:
Outputs
PSObject
Returns the output that is generated by the invoked command (the value of the Command parameter).
Here is an example:
> $x = iex "git fetch --all"
remote: Enumerating objects: 7, done.
remote: Counting objects: 100% (7/7), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 4 (delta 3), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (4/4), done.
Content of $x
:
> $x
Fetching origin
Fetching upstream
So the main information is not returned to $x
. I can't imagine that git fetch --all
is returning the main information via stderr
(wouldn't make sense ...).
I also found this PowerShell question, which is unanswered and the used PowerShell version is 2.
Used PowerShell version:
> $PSVersionTable
Name Value
---- -----
PSVersion 6.2.0
PSEdition Core
GitCommitId 6.2.0
OS Microsoft Windows 10.0.18362
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
How can I force Invoke-Expression
to return the whole output?
Thx
As I mentioned in "PowerShell Capture Git Output", with Git 2.16 (Q1 2018), you can try and set first:
Then in your Powershell script, you should get both stdout and stderr outputs,
See also
dahlbyk/posh-git
issue 109 for a more Powershell-like example: