Write-Warning

경고 메시지를 씁니다.

구문

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

설명

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

매개 변수

-Message <string>

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

필수 여부

true

위치

1

기본값

파이프라인 입력 적용 여부

true (ByValue)

와일드카드 문자 적용 여부

false

<CommonParameters>

이 cmdlet은 -Verbose, -Debug, -ErrorAction, -ErrorVariable, -OutBuffer, -OutVariable 등의 일반 매개 변수를 지원합니다. 자세한 내용은 about_commonparameters.

입력 및 출력

입력 유형은 cmdlet으로 파이프할 수 있는 개체의 유형입니다. 반환 유형은 cmdlet에서 반환되는 개체의 유형입니다.

입력

System.String

경고가 포함된 문자열을 Write-Warning으로 파이프할 수 있습니다.

출력

없음

Write-Warning은 경로 스트림에만 기록하며 다른 출력은 생성하지 않습니다.

참고

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

예 1

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

설명
-----------
이 명령은 "WARNING: This is only a test warning."이라는 메시지를 표시합니다.





예 2

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

C:\PS> $w | write-warning

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





예 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."

설명
-----------
이 예에서는 $WarningPreference 변수의 값이 Write-Warning 명령에 미치는 영향을 보여 줍니다.

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

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

$WarningPreference 변수에 대한 자세한 내용은 about_Preference_Variables를 참조하십시오.





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

설명
-----------
이 예에서는 WarningAction 일반 매개 변수가 Write-Warning 명령에 미치는 영향을 보여 줍니다. 어떤 cmdlet에서든 WarningAction 일반 매개 변수를 사용하여 해당 명령의 결과로 발생하는 경고에 Windows PowerShell이 응답하는 방식을 결정할 수 있습니다. WarningAction 일반 매개 변수는 해당 명령에 대해서만 $WarningPreference 값을 재정의합니다.

이 명령은 Write-Warning cmdlet을 사용하여 경고를 표시합니다. WarningAction 일반 매개 변수에 "Inquire"를 지정하면 명령이 경고를 표시할 때 시스템에서 사용자에게 메시지를 표시합니다.

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





참고 항목

개념

about_Preference_Variables
about_commonparameters
Write-Debug
Write-Error
Write-Host
Write-Output
Write-Progress
Write-Verbose