2012-11-26 34 views
0

我曾經在下面的VBSCRIPT中使用過數組...我不知道我應該如何在PowerShell中執行它...可以幫助我解決......?Powershell中的數組

CODE --> VBSCRIPT 
dim arrErrors(12) 
arrErrors(0) = "APP0" 
arrErrors(1) = " APP1" 
arrErrors(2) = " APP2" 
arrErrors(3) = " APP3」 
arrErrors(4) = "APP4" 
arrErrors(5) = "APP5" 
arrErrors(6) = "APP6" 
arrErrors(7) = "APP7" 
arrErrors(8) = "APP8" 
arrErrors(9) = "APP9" 
arrErrors(10) = "APP10" 
arrErrors(11) = "APP11" 
arrErrors(12) = "APP12" 
for i = 0 to ubound(arrErrors) 
    strError = arrErrors(i) 
    if (left(lcase(strErrorLine), len(strError)) = lcase(strError)) then 
    objErrorLog.WriteLine strErrorLine & vbTab & strComputer & vbTab & "Found Error number" & vbTab & i 
    exit for 
    end If 

回答

2

創建一個哈希表。用錯誤名稱和值填充它。解析錯誤字符串並查看哈希表是否包含它。像這樣,

$htErr = @{ "app0" = 0; "app1" = 1; "app2" = 2 } # Populate hash table 
$error = ... # get the error string from somewhere. 
if($htErr[$error]) { 
    "Found error, code " + $htErr[$error] # Get code based on error string 
}