The documentation you link to unfortunately doesn't reflect the fact that what Out-*
cmdlets have in common is to use PowerShell's for-display output formatting system (resulting in rich, multi-line representations of objects).
Given that logs are usually line-oriented and should ideally be suited to programmatic processing, Out
is therefore not the right verb[1] to use.
Note that PowerShell commands do not write their (regular) output to stdout (standard output) as such, given that PowerShell has a more sophisticated system of 6 output streams - see about_Redirections - where stream number 1
, the success output stream, is meant for data only.
Add
, following the example of Add-Content
, appends to an existing resource while creating it on demand.
However, this logic isn't consistent among built-in cmdlets, as some have only a create-or-replace-by-default form (e.g., Out-File
), with an optional -Append
switch as an opt-in to appending content.
Based on the above, one option is:
Use Add-Statistics
and, by default, have it output to the information stream (6
), via
Write-Information
(assuming the command is implemented in PowerShell), so it doesn't interfere with data (success-stream) output.
- Note:
Write-Information
is silent by default, which you can change via the -InformationAction
common parameter or the $InformationPreference
preference variable. Alternatively, use Write-Host
, which (in PSv5+) also writes to the information stream (6
), but its output does display by default.
Either add an -OutFile
parameter to Add-Statistics
to write to a file instead (creating it on demand), or let the caller redirect the information-stream output to a file with something like 6>log.txt
(which works even when Write-Information
output would be silent, if not redirected).
[1] As stated in the linked documentation, "verb" is used loosely here; some of PowerShell's approved verbs aren't verbs in a strict natural-language grammar sense.