¿Alguien puede explicar por qué esta secuencia de comandos arroja una excepción?La secuencia de comandos Powershell falla después de acceder a la propiedad Array.Length
$byteArray = @(1,2,3)
write-Output ("{0:X}{1:X}{2:X}" -f $byteArray)
write-Output ($byteArray.Length -ge 3)
write-Output ("{0:X}{1:X}{2:X}" -f $byteArray)
Básicamente, estoy creando una matriz de números, formateando la matriz y luego verificando su longitud y formateándola de nuevo.
El primer formato tiene éxito, pero el segundo formato arroja una excepción.
123
True
--------------------------------------------------------------------------------
POWERSHELL EXCEPTION
EXCEPTION TYPE:System.Management.Automation.RuntimeException
MESSAGE:Error formatting a string: Index (zero based) must be greater than or equal to zero and less than the size of the argument list..
POSITION:
At line:4 char:36
+ write-Output ("{0:X}{1:X}{2:X}" -f <<<< $byteArray)
--------------------------------------------------------------------------------
¿Debería ser esto en ServerFault? Tal vez no porque es un script, ¿pero no un script de administrador? –
No debería, ya que esta es claramente una pregunta sobre el comportamiento extraño de un programa y no sobre administrar nada. – Joey
+1. Esta es una pregunta fascinante (para mí), y para nada relacionada con el administrador. –