2016-06-13 73 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]