Tableaux PowerShell

De Linuxmemo.

Sommaire

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]
$tab[-3..-1]

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

Concaténation

$chaine1 = 'a','z','e','r','t','y'
$chaine2 = 'a','z','e','r','t','y'
$chaine1 + $chaine2

Ajout

$tab = 1,2,3
$tab += 4

Modification

$tab[2]=1

Suppression

Outils personnels