Write a warning message in reverse video to the host display.

      Write-Warning [-message] string [CommonParameters]

   -message string
       The warning message to send to the host.
       {may be piped}

       -Verbose, -Debug, -ErrorAction, -ErrorVariable, -WarningAction, -WarningVariable,
       -OutBuffer -OutVariable.

Setting the $WarningPreference variable will alter the action of Write-Warning:

Continue Show the message on the console [this is the Default action]
SilentlyContinue do not show the message.
Stop show the message and then halt.
Inquire prompt the user.

Write-Warning (and Write-host) write only to the host/screen, so they will be visible even if the output is redirected to file.
To also have the output passed to the success pipeline, use Write-Output instead.

Warning Sound/Beep

You can also play an Alert Sound/Beep with [console]::Beep (via Idera)

$frequency = 800
$durationMS = 2000
[console]::Beep($frequency, $durationMS)


Write a warning message:

PS C:\> $WarningPreference = "Continue"
PS C:\> Write-Warning "The quick brown fox."

“History is a vast early warning system” ~ Norman Cousins

Related PowerShell Commands:

Write-Debug - Write a debug message to the host display.
Write-Error - Write an object to the error pipeline.
Write-Host - Display objects through the host user interface.
Write-Output - Write an object to the pipeline.
Write-Progress - Display a progress bar.
Write-Verbose - Write a string to the host’s verbose display.

Copyright © SS64.com 1999-2019
Some rights reserved