Write-Warning - PowerShell


 

Writes a warning message. (Write-Warning)

   

# NAME
Write-Warning

# SYNOPSIS
Writes a warning message.

# SYNTAX
Write-Warning [-Message] <string> [<CommonParameters>]

# DESCRIPTION
The Write-Warning cmdlet writes a warning message to the Windows PowerShell host. The response to the warning depends on the value of the user's $WarningPreference variable and the use of the WarningAction common parameter.

# PARAMETERS
-Message <string>
Specifies the warning message.

Required? true
Position? 1
Default value
Accept pipeline input? true (ByValue)
Accept wildcard characters? false

<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer and OutVariable. For more information, type,
"get-help about_commonparameters".

# INPUTS
System.String
You can pipe a string that contains the warning to Write-Warning.

# OUTPUTS
None
Write-Warning writes only to the warning stream. It does not generate any other output.

# NOTES

The default value for the $WarningPreference variable is "Continue", which displays the warning and then continues executing the command. To determine valid values for a preference variable such as $WarningPreference, set it to a string of random characters, such as "abc". The resulting error message will list the valid values.

# EXAMPLE 1

C:\PS>write-warning "This is only a test warning."

# Description
-----------
This command displays the message "WARNING: This is only a test warning."

# EXAMPLE 2

C:\PS>$w = "This is only a test warning."

C:\PS> $w | write-warning

# Description
-----------
This example shows that you can use a pipeline operator (|) to send a string to Write-Warning. You can save the string in a variable, as shown in this command, or pipe the string directly to Write-Warning.

# EXAMPLE 3

C:\PS>$warningpreference

Continue

C:\PS> write-warning "This is only a test warning."
This is only a test warning.

C:\PS> $warningpreference = "SilentlyContinue"

C:\PS> write-warning "This is only a test warning."
C:\PS>

C:\PS> $warningpreference = "Stop"

C:\PS> write-warning "This is only a test warning."
WARNING: This is only a test message.
Write-Warning : Command execution stopped because the shell variable "WarningPreference" is set to Stop.
At line:1 char:14
+ write-warning <<<< "This is only a test message."

# Description
-----------
This example shows the effect of the value of the $WarningPreference variable on a Write-Warning command.

The first command displays the default value of the $WarningPreference variable, which is "Continue". As a result, when you write a warning, the warning message is displayed and execution continues.

When you change the value of the $WarningPreference variable, the effect of the Write-Warning command changes again. A value of "SilentlyContinue" suppresses the warning. A value of "Stop" displays the warning and then stops execution of the command.

For more information about the $WarningPreference variable, see about_Preference_Variables.

# EXAMPLE 4

C:\PS>write-warning "This is only a test warning." -warningaction Inquire

WARNING: This is only a test warning.

Confirm
Continue with this operation?
[Y] Yes [A] Yes to All [H] Halt Command [S] Suspend [?] Help (default is "Y"):

# Description
-----------
This example shows the effect of the WarningAction common parameter on a Write-Warning command. You can use the WarningAction common parameter with any cmdlet to determine how Windows PowerShell responds to warnings resulting from that command. The WarningAction common parameter overrides the value of the $WarningPreference only for that particular command.

This command uses the Write-Warning cmdlet to display a warning. The WarningAction common parameter with a value of "Inquire" directs the system to prompt the user when the command displays a warning.

For more information about the WarningAction common parameter, see about_CommonParameters.

RELATED LINKS
Online version: http://go.microsoft.com/fwlink/?LinkID=113430
about_Preference_Variables
about_CommonParameters
Write-Debug
Write-Error
Write-Host
Write-Output
Write-Progress
Write-Verbose

C:\Windows>powershell get-help Write-Error -full

ColorConsole [Version 1.7.1000] PowerShell 2.0-Export
Microsoft Windows [Version 6.1.7600]
Copyright (c) 2014 Microsoft Corporation.

OS: Windows 10, 8.1, 8, 7, Vista / Windows Server 2016, 2012, 2008
»»»» ColorConsole








Windows-10





Windows-10

... facebook.de
... Windows-10 FAQ
... Windows-10 Info


Become a Sponsor
... Your button here?





PowerShell: Writes a warning message.

HTTP: ... PS_Windows/en/Write-Warning.htm
0.155
9382

Dateien von Festplatte öffnen sich nicht sofort?

 /

Open paths in the history of the Explorer Views directly!

 /

How to create at once several subfolders levels (commando-line)?

 /

Kann man im Windows-7 Explorer die Verzeichnisstuktur ausblenden?

 /

Schutz vor Viren, Trojanern und Schadsoftware auf Windows 10, aber wie?

 /

Run directly minimized to tray without to see the main window?

 /

How to grant a folder / directory access for a program under Windows 10 Explorer?

 /

Direct access to the switch-off, standby, logout, hibernation!

 /

Windows 10 notification "Turn-on virus protection", can I turn off this message?

 /

What is a documents folder?

 /

How can auto start the Mouse Pointer-Stick with Windows?

 /

Can I filter certain file types in the folder contents printing?

 /