IN POWERSHELL write a script that retrieves a collection of objects (an array) loops them through a foreach loop and displays one property of the object with the write-host cmdlet.
Following is a script in powershell that initiates a array of fruits and loops through them by a foreach loop and displays the object using write-host.
here,
TO RUN : & ".\run.ps1"
FILE : run.ps1
$fruits = @("mango","apple","banana","guava","peaches","melons")
foreach ($fruit in $fruits) {
Write-Host $fruit
}
OUTPUT:
mango
apple
banana
guava
peaches
melons
Get Answers For Free
Most questions answered within 1 hours.