Write-Warning

경고 메시지를 씁니다.

Syntax

Write-Warning
     [-Message] <String>
     [<CommonParameters>]

Description

cmdlet은 Write-Warning PowerShell 호스트에 경고 메시지를 씁니다. 경고에 대한 응답은 사용자 $WarningPreference 변수의 값과 WarningAction 일반 매개 변수의 사용에 따라 달라집니다.

예제

예제 1: 경고 메시지 작성

이 명령은 "경고: 테스트 경고일 뿐입니다."라는 메시지를 표시합니다.

Write-Warning "This is only a test warning."

예제 2: 쓰기 경고에 문자열 전달

이 명령은 파이프라인 연산자(|)를 사용하여 문자열 Write-Warning을 보낼 수 있음을 보여 줍니다. 이 명령에 표시된 대로 변수에 문자열을 저장하거나 문자열을 직접 파이프할 수 있습니다 Write-Warning.

$w = "This is only a test warning."
$w | Write-Warning

예제 3: $WarningPreference 변수 설정 및 경고 작성

이 예제에서는 명령에 대한 변수 값의 $WarningPreference 효과를 보여 있습니다 Write-Warning .

PS> $WarningPreference
Continue
PS> Write-Warning "This is only a test warning."
This is only a test warning.
PS> $WarningPreference = "SilentlyContinue"
PS> Write-Warning "This is only a test warning."
PS> $WarningPreference = "Stop"
PS> Write-Warning "This is only a test warning."
WARNING: This is only a test warning.
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 warning."

첫 번째 명령은 변수의 기본값인 Continue.을 $WarningPreference 표시합니다. 따라서 경고를 작성하면 경고 메시지가 표시되고 실행이 계속됩니다.

변수 값을 $WarningPreference 변경하면 명령의 Write-Warning 효과가 다시 변경됩니다. 값은 SilentlyContinue 경고를 표시하지 않습니다. 값 Stop 은 경고를 표시한 다음 명령 실행을 중지합니다.

변수에 대한 $WarningPreference 자세한 내용은 about_Preference_Variables 참조하세요.

예제 4: WarningAction 매개 변수 설정 및 경고 작성

이 예제에서는 WarningAction 일반 매개 변수 Write-Warning명령에 미치는 영향을 보여줍니다. 모든 cmdlet에서 WarningAction 공통 매개 변수를 사용하여 PowerShell이 해당 명령으로 인한 경고에 응답하는 방법을 결정할 수 있습니다. WarningAction 공통 매개 변수는 해당 특정 명령에 대한 유일한 값을 재정의 $WarningPreference 합니다.

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"):

이 명령은 cmdlet을 Write-Warning 사용하여 경고를 표시합니다. Inquire 값이 있는 WarningAction 일반 매개 변수는 명령에 경고가 표시되면 사용자에게 메시지를 표시하도록 시스템에 지시합니다.

WarningAction 일반 매개 변수에 대한 자세한 내용은 about_CommonParameters 참조하세요.

매개 변수

-Message

경고 메시지를 지정합니다.

Type:String
Aliases:Msg
Position:0
Default value:None
Required:True
Accept pipeline input:True
Accept wildcard characters:False

입력

String

경고가 포함된 문자열을 이 cmdlet에 파이프할 수 있습니다.

출력

None

이 cmdlet은 출력을 반환하지 않습니다. 경고 스트림에만 씁니다.

참고

변수의 $WarningPreference 기본값은 Continue경고를 표시한 다음 명령을 계속 실행하는 것입니다. 같은 $WarningPreference기본 설정 변수에 유효한 값을 확인하려면 "abc"와 같은 임의의 문자 문자열로 설정합니다. 결과 오류 메시지에 유효한 값이 나열됩니다.