Write Information - PowerShell


Overview

Write-Information displays information messages in the PowerShell console with customizable formatting options. It’s ideal for providing detailed feedback, alerts, or other non-error messages during script execution.

Syntax

Write-Information [-Message] <string> [-Id <string>] [-InformationAction <InformationAction>] [-Category <string>] [-TargetObject <psobject>] [-Severity <InformationSeverity>] [-AudioSource <string>] [-RenderingCulture <cultureinfo>] [-OutVariable <string>] [-PassThru]

Options/Flags

  • -Message: The information message to display.
  • -Id: A unique identifier for the message.
  • -InformationAction: Specifies the action to take based on the information message (Continue, Ignore, or Suspend). Default: Continue.
  • -Category: The category of the information message.
  • -TargetObject: The object associated with the information message.
  • -Severity: The severity level of the message (Critical, Error, Warning, Verbose, or Debug). Default: Information.
  • -AudioSource: The source of the information message.
  • -RenderingCulture: Specifies the culture for formatting the message. Default: Current culture.
  • -OutVariable: Stores the output in a variable instead of displaying it on the console.
  • -PassThru: Passes the input object through to the output.

Examples

Simple information message:

Write-Information -Message "Script completed successfully."

Message with identifier and category:

Write-Information -Message "Insufficient permissions detected." -Id "PermissionError" -Category "Security"

Message with custom severity and action:

Write-Information -Message "Database disconnected. Reconnecting..." -Severity Warning -InformationAction Ignore

Common Issues

  • Message not displayed: Ensure the -Message parameter is specified.
  • Unrecognized severity level: Use only the valid severity levels listed in the -Severity parameter description.

Integration

Combine with other commands:

Get-Service | Where-Object {$_.Status -ne "Running"} | Write-Information -InformationAction Suspend -Message "Stopped services detected"

Use in scripts:

function Log-Information {
    param (
        [string]$Message,
        [InformationSeverity]$Severity = [InformationSeverity]::Information
    )
    Write-Information -Message $Message -Severity $Severity
}
  • Write-Error: Displays error messages.
  • Write-Warning: Displays warning messages.
  • Write-Verbose: Displays verbose information.
  • Write-Debug: Displays debug information.