FoxDeploy's helpful answer contains the crucial pointer, but let me offer a (corrected) PowerShell-idiomatic reformulation of your code.
Get-ChildItem -File -Recurse | Select-Object -Property @{
label = 'Git commit'
expr = { git log -1 --format=format:%s -- $_.FullName }
},
@{
label = 'Size(KB)'
expr = { '{0:0.00}' -f ($_.Length/1KB) }
}, LastWriteTime, FullName
Note:
Calling native executables in calculated properties:
Generally, note that there's nothing fundamentally special about calling native executables from the expression
script block ({ ... }
) of a calculated property.
Specifically, the following considerations apply:
In PowerShell, stdout output from native executables is invariably converted to text ([string]
instances). If the output comprises multiple lines, the property values becomes a (regular [object[]]
) array containing strings.
- If the native executable produces no stdout output, the value of the property is "nothing", i.e. the so-called "Automation Null" value (
[System.Management.Automation.Internal.AutomationNull]::Value
) that in most context behaves like $null
.
Any stderr output from the native executable is quietly discarded. (Analogously, errors from PowerShell commands or expressions in expression
script blocks are quietly ignored.)
Therefore, in order to troubleshoot an expression
script block, execute it stand-alone, via a ForEach-Object
command (whose built-in alias is %
), so as to surface any errors; e.g.:
# Uses broken `git` syntax; note the resulting error message.
PS> (Get-ChildItem -File)[0] | % { git log -1 --format:format=%s -- $_.FullName }
fatal: unrecognized argument: --format:format=%s
As for what you tried:
Because your git
command was syntactically incorrect, git
only produced stderr output, which PowerShell then ignored, as explained above.
Thus, your Git commit
properties ended up containing "nothing", which simply renders blank in output formatting.