2016-06-13 75 views
0

這是我第一次嘗試使用任何語言的腳本。我知道我想做什麼,但可以使用一些幫助找到我要找的東西。這是我自己的學習和樂趣:)PowerShell數據類型和散列表MCA_Decode

  1. 需要1個參數(兩個字節十六進制或二進制)
  2. 比較反對錯誤方項目掩蓋
  3. 寫主機與解釋

當前數據類型都可能是字符串。我需要這些是intint32int64

錯誤口罩簡單的賦值給變量

$IO_Error = 0000111000001011 

會是更有效的將這些存儲爲「哈希表」

$ErrorList = @{IO_Error, 0000111000001011; so, on; so, on;} 

然後能的foreach檢查是否匹配?

這適用於簡單的錯誤,但進入複合錯誤代碼和掩碼我需要能夠引用和檢查某些偏移量以查看設置了哪些位以確保精確解碼。

<# 
# ===================== 
# Simple Error Codes      # Table 15-8. IA32_MCi_Status [15:0] Simple Error Code Encoding 
# =====================      # 64-ia-32-architectures-software-developer-manual-325462. Volume 3B 
# 
# 
#   Error Desc     Error Mask   Error Code Binary Encoding Meaning 
# No Error       0000 0000 0000 0000 No error has been reported to this bank of error-reporting registers. 
# Unclassified      0000 0000 0000 0001 This error has not been classified into the MCA error classes. 
# Microcode ROM Parity Error  0000 0000 0000 0010 Parity error in internal microcode ROM 
# External Error     0000 0000 0000 0011 The BINIT# from another processor caused this processor to enter machine check.*1 
# FRC Error       0000 0000 0000 0100 FRC (functional redundancy check) master/slave error 
# Internal Parity Error    0000 0000 0000 0101 Internal parity error. 
# SMM Handler Code Access Violation 0000 0000 0000 0110 An attempt was made by the SMM Handler to execute outside the ranges specified by SMRR. 
# Internal Timer Error    0000 0100 0000 0000 Internal timer error. 
# I/O Error       0000 1110 0000 1011 generic I/O error. 
# Internal Unclassified    0000 01xx xxxx xxxx Internal unclassified errors. *2 
# 
# 
# ===================== 
# Compound Error Codes      # Table 15-9 IA32_MCi_Status [15:0] Compound Error Code Encounding 
# =====================      # 64-ia-32-architectures-software-developer-manual-325462. Volume 3B 
# 
# 
#   Error Desc     Error Mask   Error Code Binary Encoding Meaning 
# Generic Cache Hierarchy   000F 0000 0000 11LL Generic cache hierarchy error 
# TLB Errors      000F 0000 0001 TTLL {TT}TLB{LL}_ERR 
# Memory Controller Errors   000F 0000 1MMM CCCC {MMM}_CHANNEL{CCCC}_ERR 
# Cache Hierarchy Errors   000F 0001 RRRR TTLL {TT}CACHE{LL}_{RRRR}_ERR 
# Bus and Interconnect Errors  000F 1PPT RRRR IILL BUS{LL}_{PP}_{RRRR}_{II}_{T}_ERR 
# 
#---------------------------------------------------------------------------------------------------------------------------------------------- 
#> 
Function MCA_Decode 
{ 
$No_Error = 0000000000000000 
$Unclassified = 0000000000000001 
$Microcode_ROM_Parity_Error = 0000000000000010 
$External_Error = 0000000000000011 
$FRC_Error = 0000000000000100 
$Internal_Parity_Error = 0000000000000101 
$SMM_Handler_Code_Access_Violation = 0000000000000110 
$Internal_Timer_Error = 0000010000000000 
$IO_Error = 0000111000001011 
#$Internal_Unclassified = 000001xx xxxx xxxx 
# 
# 
$input = $args[0] 
if($input -eq $No_Error){ 
Write-Host "Error Type: No Error`nError Desc: No error has been reported to this bank of error-reporting registers." -ForegroundColor Green 
} 
if($input -eq $Unclassified){ 
Write-Host "Error Type: Unclassified`nError Desc: This error has not been classified into the MCA error classes." -ForegroundColor Green 
} 
if($input -eq $Microcode_ROM_Parity_Error){ 
Write-Host "Error Type: Microcode ROM Parity Error`nError Desc: Parity error in internal microcode ROM" -ForegroundColor Green 
} 
if($input -eq $External_Error){ 
Write-Host "Error Type: External Error`nError Desc: The BINIT# from another processor caused this processor to enter machine check." -ForegroundColor Green 
} 
if($input -eq $FRC_Error){ 
Write-Host "Error Type: FRC Error`nError Desc: FRC (functional redundancy check) master/slave error" -ForegroundColor Green 
} 
if($input -eq $Internal_Parity_Error){ 
Write-Host "Error Type: Internal Parity Error`nError Desc: Internal parity error." -ForegroundColor Green 
} 
if($input -eq $SMM_Handler_Code_Access_Violation){ 
Write-Host "Error Type: SMM Handler Code Access Violation`nError Desc: An attempt was made by the SMM Handler to execute outside the ranges specified by SMRR." -ForegroundColor Green 
} 
if($input -eq $Internal_Timer_Error){ 
Write-Host "Error Type: Internal Timer Error`Error Desc: Internal timer error." -ForegroundColor Green 
} 
if($input -eq $IO_Error){ 
Write-Host "Error Type: I/O Error`Error Desc: generic I/O error." -ForegroundColor Green 
} 
} 
MCA_Decode $args[0] 
+0

得到的一切使用幫助工作只是爲了澄清,該變量其實都是「字符串」 $ IO_Error.GetTypeCode() 字符串 – genperf

+0

只是爲了澄清,該變量在事實上所有的「字符串」 $ IO_Error.GetTypeCode() 字符串 所以我可以很容易地發送我的變量| gm然而,對於從來沒有玩過這個定義是不容易解釋的人,例如這個很容易 長度屬性int長度{獲得;} if($ input.Length -le 4){[convert ] :: ToString(「$ input」,2)} ..... 我知道兩個字節的十六進制輸入將是4個字符長,所以這可以測試,如果十六進制我可以轉換爲二進制。 什麼是不明確的是我需要這些值是Ints和什麼樣的 – genperf

回答

0

散列表當然可以幫助您解決個別錯誤。

我可以建議在十六進制中定義您的錯誤代碼值,PowerShell本地解析它,它更容易讀取IMO。另外,如果您打算引入複合錯誤,請確保每個位代表一個明顯的原始錯誤。

你可以這樣做:

function Get-ErrorDescription { 
    param(
     [int]$ErrorCode, 
     [switch]$All 
    ) 

    $ErrorCodes = @{ 
     0x0000 = 'No_Error' 
     0x0001 = 'Unclassified' 
     0x0002 = 'Microcode_ROM_Parity_Error' 
     0x0004 = 'External_Error' 
     0x0008 = 'FRC_Error' 
     0x0010 = 'Internal_Parity_Error' 
     0x0020 = 'SMM_Handler_Code_Access_Violation' 
     0x0040 = 'Internal_Timer_Error' 
     0x0080 = 'IO_Error' 
     0x0100 = 'IRQ_Error' 
     0x0062 = 'Compound_Error' 
    } 

    if(-not $All -or $ErrorCode -eq 0){ 
     # default, return just the exact error 
     return $ErrorCodes[$ErrorCode] 
    } 

    # Sort keys, filter out No_Error and test the $ErrorCode against each errorcode value with binary AND, output the error description 
    return $ErrorCodes.Keys |Sort-Object |Where-Object {$_ -ne 0 -and (($ErrorCode -band $_) -eq $_)}|ForEach-Object { $ErrorCodes[$_] } 
} 

現在,您可以通過數值解析錯誤:

PS C:\> Get-ErrorDescription 0x0000 
No_Error 
PS C:\> Get-ErrorDescription 0x0001 
Unclassified 
PS C:\> Get-ErrorDescription 0x0062 
Compound_Error 
PS C:\> Get-ErrorDescription 0x0062 
Microcode_ROM_Parity_Error 
SMM_Handler_Code_Access_Violation 
Internal_Timer_Error 
Compound_Error 
PS C:\> Get-ErrorDescription 0x0013 
Unclassified 
Microcode_ROM_Parity_Error 
Internal_Parity_Error 
0

感謝您的幫助。 我能夠從這個https://technet.microsoft.com/en-us/library/ee692803.aspx

function Get-MCAError{ 
[CmdletBinding()] 
[string]$Errorcode = $args[0] 
$ErrorCodes = @{ 
    '0x0000' = 'Verbose message here'; 
...5000+ lines 
}#end of hash table 
if ($ErrorCodes.ContainsKey($Errorcode) -eq $True){ 
$Decode_Message = $ErrorCodes.get_item($Errorcode) 
Write-Host $Decode_Message -ForegroundColor Green 
} #End of hash lookup 
else { 
Write-Host "Error Not Found, or Internal Unclassified" -ForegroundColor Red 
} #End of Else 
} #End of Get-MCAError Function 
Get-MCAError $args[0]