PowerShell Remover item [0] de uma matriz
Estou com um pouco de dificuldade para remover a primeira linha (ID do item) de uma matriz.
$test.GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True Object[] System.Array
Para listar todas as opções que tentei,$test | gm
e afirma claramente:
Remove Method, void IList.Remove(System.Object value)
RemoveAt Method void IList.RemoveAt(int index)
Então, quando eu tento$test.RemoveAt(0)
Eu recebo o erro:
Exception calling "RemoveAt" with "1" argument(s): "Collection was of a fixed size."At line:1 char:1
+ $test.RemoveAt(1)
+ ~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : NotSupportedException
Então eu finalmente encontreiaqui que minha matriz precisa ser do tipoSystem.Object
poder usar$test.RemoveAt(0)
. É uma prática recomendada declarar todas as matrizes no início do script como uma lista? Ou é melhor converter as matrizes com$collection = ({$test}.Invoke())
para uma lista mais tarde, quando essa funcionalidade é necessária?
Quais são os prós e contras dos dois tipos? Obrigado pela ajuda.