Tableaux PowerShell

De Linuxmemo.

Déclaration (d'un tableau vide)

$NomTableau = @()

ou avec tun typage

[String[]]$NomTableau = @()

Déclaration avec initialisation en même temps

$tab = @(1,5,9,10,6)
ou 
$tab = 1,5,9,10,6

Lecture d'un tableau

$tab[0]
$tab[0,2]
$tab[1..20
  • Dernier indice
$tab[$tab.length-1]
ou
$tab[-1]

Quand on utilise un indice négatif, on fait référence depuis la fin du tableau.

Outils personnels