Массивы в PowerShell

Введение

В этой статье вы можете прочитать про массивы в PowerShell.

Проверить на принадлежность

Проверить содержится ли определённое значение в массиве можно с помощью contains или in

$array = 1..10 $x = 6 if ($array -contains $x) {Write-Host "Contains"}

.\demo.ps1

Contains

$array = "beget.com", "heihei.website", "aredel.com", "topbicycle.ru" $url = "aredel.com" if ($url -in $array) {Write-Host "In"}

.\demo.ps1

In

foreaach

$collection = 1..10 foreach ($number in $collection) { Write-Host "Current Number: $number" }

.\demo.ps1

Current Number: 1 Current Number: 2 Current Number: 3 Current Number: 4 Current Number: 5 Current Number: 6 Current Number: 7 Current Number: 8 Current Number: 9 Current Number: 10

$collection = "beget.com", "heihei.website", "aredel.com", "topbicycle.ru" foreach ($url in $collection) { Write-Host "Current URL: $url" }

.\demo.ps1

Current URL: beget.com Current URL: heihei.website Current URL: aredel.com Current URL: topbicycle.ru

Автор статьи: Андрей Олегович

Изображение баннера