Get-Error
Geçerli oturumdaki en son hata iletilerini alır ve görüntüler.
Sözdizimi
Newest EnterprisePublishing
Get-Error
[[-Newest] <Int32>]
[<CommonParameters>]
Error
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.
Parametre özellikleri
| Tür: | PSObject |
| Default value: | None |
| Joker karakterleri destekler: | False |
| DontShow: | False |
Parametre kümeleri
Error
| Position: | Named |
| Zorunlu: | False |
| İşlem hattından gelen değer: | True |
| Özellik adına göre işlem hattından gelen değer: | False |
| Kalan bağımsız değişkenlerden elde edilen değer: | False |
-Newest
Geçerli oturumda oluşan görüntülenecek hata sayısını belirtir.
Parametre özellikleri
| Tür: | Int32 |
| Default value: | None |
| Joker karakterleri destekler: | False |
| DontShow: | False |
| Diğer adlar: | Son |
Parametre kümeleri
Newest
| Position: | 0 |
| Zorunlu: | False |
| İşlem hattından gelen değer: | False |
| Özellik adına göre işlem hattından gelen değer: | False |
| Kalan bağımsız değişkenlerden elde edilen değer: | False |
CommonParameters
Bu cmdlet yaygın parametreleri destekler: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction ve -WarningVariable. Daha fazla bilgi için bkz. about_CommonParameters.
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.