Aracılığıyla paylaş


Get-Error

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

Syntax

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

Description

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

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

Cmdlet, Get-Error geçerli oturumdan birden çok hata görüntülemek için gibi $Errorbir 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 sayıda hata iletisini alma

Bu örnekte, En Yeni parametresiyle nasıl kullanılacağı Get-Error 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ı iletiler almak için bir hata koleksiyonu gönderme

Otomatik $Error değişken, geçerli oturumdaki bir hata nesneleri dizisini içerir. Ayrıntılı hata iletileri almak için nesne dizisine Get-Error kanal oluşturulabilir.

Bu örnekte cmdlet'ine $ErrorGet-Error kanal oluşturulur. 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.

Type:PSObject
Position:Named
Default value:None
Required:False
Accept pipeline input:True
Accept wildcard characters:False

-Newest

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

Type:Int32
Aliases:Last
Position:0
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

Girişler

PSObject

Herhangi bir PSObject'ten girişi destekler, ancak ErrorRecord veya Exception nesnesi sağlanmadığı sürece sonuçlar farklılık gösterir.

Çıkışlar

ErrorRecord

PSExtendedError nesnesinde çıkış.

Notlar

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