Collections:
Other Resources:
Loop Array Elements in Windows PowerShell Scripts
How to loop through all elements in an array in Windows PowerShell scripts?
✍: FYIcenter.com
An array has a special property called "Length", which holds the length of the array
or the number of members in the array.
The "Length" property can help you to loop through all members using a simple "For {...}" loop as shown below:
$w = @("Sun","Mon","Tue","Wed","Thu","Fri","Sat")
"There are "+$w.Length+" days in a week:"
For ($i=0; $i -lt $w.Length; $i++) {
" "+$w[$i]
}
You can also the "Foreach (...) {...}" loop to loop through each member in array as show in the following example:
$w = @("Sun","Mon","Tue","Wed","Thu","Fri","Sat")
"Week days:"
Foreach ($d in $w) {
" "+$d
}
⇒ Hashtable in Windows PowerShell Scripts
⇐ Array in Windows PowerShell Scripts
2016-10-29, ∼3062🔥, 0💬
Popular Posts:
Why I am getting this "Microsoft Silverlight Update" pop up window? If you have Silverlight 2.0 inst...
What is "Remote Desktop Services UserMode Port Redirector" in my Windows XP service list? And how is...
What is pdf.ocx - ActiveX - Adobe Acrobat Control Version 6.0 for ActiveX? ActiveX pdf.ocx is instal...
What is "@%SystemRoot%\ehome\ehs ched.exe,-101"in my Windows 7 service list? And how is "@%SystemRoo...
the computer detect the microphone plugged in, but it's not working with any App. or Desktop soft we...