Aracılığıyla paylaş


Get-Error

Geçerli oturumdaki en son hata iletilerini alır ve görüntüler.

Sözdizimi

Get-Error
   [[-Newest] <Int32>]
   [<CommonParameters>]
Get-Error
   [-InputObject <PSObject>]
   [<CommonParameters>]

Description

Get-Error cmdlet'i, oturumda gerçekleşen son hatanın geçerli hata ayrıntılarını temsil eden bir PSExtendedError nesnesi alır.

Get-Error parametresini kullanarak geçerli oturumda oluşan belirli sayıda hatayı görüntülemek için kullanabilirsiniz.

Get-Error cmdlet'i, geçerli oturumdaki birden çok hatayı görüntülemek için $Errorgibi bir koleksiyondan hata nesneleri de alır.

Örnekler

Örnek 1: En son hata ayrıntılarını alma

Bu örnekte, Get-Error geçerli oturumda oluşan en son hatanın ayrıntılarını görüntüler.

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 :

Örnek 2: Geçerli oturumda oluşan belirtilen hata iletisi sayısını alma

Bu örnekte, Get-ErrorEn Yeni parametresiyle nasıl kullanılacağı gösterilmektedir. Bu örnekte, En Yeni, bu oturumda oluşan en yeni 3 hatanın ayrıntılarını döndürür.

Get-Error -Newest 3

Örnek 3: Ayrıntılı iletileri almak için bir hata koleksiyonu gönderme

$Error otomatik değişkeni, geçerli oturumdaki hata nesnelerinin bir dizisini içerir. Ayrıntılı hata iletilerini almak için nesne dizisi Get-Error aktarılabilir.

Bu örnekte, $ErrorGet-Error cmdlet'ine yöneltilir. sonuç, Örnek 1'in sonucuna benzer şekilde ayrıntılı hata iletilerinin listesidir.

$Error | Get-Error

Parametreler

-InputObject

Bu parametre işlem hattı girişi için kullanılır.

Tür:PSObject
Position:Named
Default value:None
Gerekli:False
İşlem hattı girişini kabul et:True
Joker karakterleri kabul et:False

-Newest

Geçerli oturumda oluşan görüntülenecek hata sayısını belirtir.

Tür:Int32
Diğer adlar:Last
Position:0
Default value:None
Gerekli:False
İşlem hattı girişini kabul et:False
Joker karakterleri kabul et:False

Girişler

PSObject

Bu cmdlet'e herhangi PSObject kanal oluşturabilirsiniz, ancak sonuçlar ErrorRecord veya Özel Durum nesnesi sağlanmadığı sürece değişir.

Çıkışlar

ErrorRecord

Bu cmdlet bir PSExtendedError nesnesi döndürür.

Notlar

PowerShell, Get-Erroriçin aşağıdaki diğer adları içerir:

  • Tüm platformlar:
    • gerr

Get-Error işlem hattı girişini kabul eder. Örneğin, $Error | Get-Error.