Powershell中的阵列

Powershell中的阵列,powershell,powershell-2.0,powershell-3.0,Powershell,Powershell 2.0,Powershell 3.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) = "AP

我曾经在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 

创建一个哈希表。用错误名称和值填充它。解析错误字符串并查看哈希表是否包含它。这样,

$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
}