InformationVariable is a PowerShell common parameter that captures Information stream messages in a variable instead of cluttering normal output. Use it with commands that emit Write-Information messages; the alias -IV is available. section 13.4 section 13.4.1
Use the captured records to control visibility and inspect context:
- Run with -InformationAction Continue to display messages while also capturing them. section 13.4
- Run with -InformationVariable inf to suppress normal display and collect records in $inf. section 13.4.1
- Filter captured InformationRecord objects through properties such as Tags and MessageData. section 13.4 section 13.4.1
Capture and filter tagged messages
Example -InformationAction SilentlyContinue -IV x; then use $x | Where-Object Tags -in @('notice') to retain only notice messages. section 13.4
Function Example {
[CmdletBinding()]
Param()
Write-Information "First message" -tag status
Write-Information "Note that this had no parameters" -tag notice
Write-Information "Second message" -tag status
}
Example -InformationAction Continue -InformationVariable x
Shows a function emitting tagged messages and a call that displays and captures them. section 13.4
