0

我曾经在 VBSCRIPT 中使用数组,如下所示……我不确定我应该如何在 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 
4

1 回答 1

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
} 
于 2012-11-26T08:06:48.343 回答