Get-Error
현재 세션의 가장 최근 오류 메시지를 가져오고 표시합니다.
구문
Newest (기본값)
Get-Error
[[-Newest] <Int32>]
[<CommonParameters>]
Error
Get-Error
[-InputObject <PSObject>]
[<CommonParameters>]
Description
Get-Error cmdlet은 세션에서 발생한 마지막 오류의 현재 오류 세부 정보를 나타내는 PSExtendedError 개체를 가져옵니다.
Get-Error 사용하여 Newest 매개 변수를 사용하여 현재 세션에서 발생한 지정된 수의 오류를 표시할 수 있습니다.
또한 Get-Error cmdlet은 컬렉션에서 $Error같은 오류 개체를 수신하여 현재 세션에서 여러 오류를 표시합니다.
예제
예제 1: 최신 오류 세부 정보 가져오기
이 예제에서는 Get-Error 현재 세션에서 발생한 가장 최근 오류의 세부 정보를 표시합니다.
Get-ChildItem -Path /NoRealDirectory
Get-Error
Get-ChildItem: Cannot find path 'C:\NoRealDirectory' because it does not exist.
Exception :
ErrorRecord :
Exception :
Message : Cannot find path 'C:\NoRealDirectory' because it does not exist.
HResult : -2146233087
TargetObject : C:\NoRealDirectory
CategoryInfo : ObjectNotFound: (C:\NoRealDirectory:String) [], ParentContainsErrorRecordException
FullyQualifiedErrorId : PathNotFound
ItemName : C:\NoRealDirectory
SessionStateCategory : Drive
TargetSite :
Name : GetChildItems
DeclaringType : System.Management.Automation.SessionStateInternal
MemberType : Method
Module : System.Management.Automation.dll
StackTrace :
at System.Management.Automation.SessionStateInternal.GetChildItems(String path, Boolean recurse, UInt32 depth,
CmdletProviderContext context)
at System.Management.Automation.ChildItemCmdletProviderIntrinsics.Get(String path, Boolean recurse, UInt32
depth, CmdletProviderContext context)
at Microsoft.PowerShell.Commands.GetChildItemCommand.ProcessRecord()
Message : Cannot find path 'C:\NoRealDirectory' because it does not exist.
Source : System.Management.Automation
HResult : -2146233087
TargetObject : C:\NoRealDirectory
CategoryInfo : ObjectNotFound: (C:\NoRealDirectory:String) [Get-ChildItem], ItemNotFoundException
FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand
InvocationInfo :
MyCommand : Get-ChildItem
ScriptLineNumber : 1
OffsetInLine : 1
HistoryId : 57
Line : Get-ChildItem -Path C:\NoRealDirectory
PositionMessage : At line:1 char:1
+ Get-ChildItem -Path C:\NoRealDirectory
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
InvocationName : Get-ChildItem
CommandOrigin : Internal
ScriptStackTrace : at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo :
예제 2: 현재 세션에서 발생한 지정된 오류 메시지 수 가져오기
이 예제에서는 Get-Error 매개 변수와 함께 사용하는 방법을 보여줍니다. 이 예제에서 Newest 이 세션에서 발생한 3개의 최신 오류에 대한 세부 정보를 반환합니다.
Get-Error -Newest 3
예제 3: 자세한 메시지를 수신하는 오류 컬렉션 보내기
$Error 자동 변수는 현재 세션의 오류 개체 배열을 포함합니다. 개체 배열을 Get-Error 파이프하여 자세한 오류 메시지를 받을 수 있습니다.
이 예제에서는 $ErrorGet-Error cmdlet에 파이프됩니다. 결과는 예제 1의 결과와 유사한 자세한 오류 메시지 목록입니다.
$Error | Get-Error
매개 변수
-InputObject
이 매개 변수는 파이프라인 입력에 사용됩니다.
매개 변수 속성
| 형식: | PSObject |
| Default value: | None |
| 와일드카드 지원: | False |
| DontShow: | False |
매개 변수 집합
Error
| Position: | Named |
| 필수: | False |
| 파이프라인의 값: | True |
| 속성 이름별 파이프라인의 값: | False |
| 나머지 인수의 값: | False |
-Newest
현재 세션에서 발생한 오류 수를 지정합니다.
매개 변수 속성
| 형식: | Int32 |
| Default value: | None |
| 와일드카드 지원: | False |
| DontShow: | False |
| 별칭: | 지난 |
매개 변수 집합
Newest
| Position: | 0 |
| 필수: | False |
| 파이프라인의 값: | False |
| 속성 이름별 파이프라인의 값: | False |
| 나머지 인수의 값: | False |
CommonParameters
이 cmdlet은 일반적인 매개 변수인 -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction 및 -WarningVariable 매개 변수를 지원합니다. 자세한 내용은 about_CommonParameters를 참조하세요.
입력
PSObject
PSObject 이 cmdlet으로 파이프할 수 있지만 ErrorRecord 또는 Exception 개체가 제공되지 않는 한 결과가 달라집니다.
출력
ErrorRecord
이 cmdlet은 PSExtendedError 개체를 반환합니다.
참고
PowerShell에는 Get-Error에 대한 다음과 같은 별칭들이 포함되어 있습니다.
- 모든 플랫폼:
gerr
Get-Error 파이프라인 입력을 허용합니다. 예: $Error | Get-Error.