Try adding your objects to an array like below

$objects = [System.Collections.ArrayList]@()

$myObject = [PSCustomObject]@{
    Name     = 'Kevin'
    Language = 'PowerShell'
    State    = 'Texas'
}


$objects.add($myObject)

$myObject1= [PSCustomObject]@{
    Name     = 'Kevin'
    Language = 'PowerShell'
    State    = 'Texas'
}


  $objects.add($myObject1)

foreach(objects){

$obj.firstname

}
Answer from TheGameiswar on Stack Overflow
🌐
Microsoft
devblogs.microsoft.com › dev blogs › scripting blog [archived] › basics of powershell looping: foreach
Basics of PowerShell Looping: Foreach - Scripting Blog [archived]
April 28, 2014 - In Windows PowerShell, if I add 5 to my $d variable, I end up actually adding the value as another element in the array. This is shown here: ... To add the number five to each of the elements in the array, I need to walk through the array by using the Foreach command.
🌐
Saved Keystrokes
savedkeystrokes.github.io › powershell › 2017 › 09 › 15 › array-foreach.html
PowerShell: $array.ForEach({}) | Saved Keystrokes
September 15, 2017 - $items.ForEach({ # This exposes the $_ object, but I find that it doesn't know what each item is. # So I often find myself setting that to a new variable. $item = $_ #I guess as you learn more and more you become versed in the ways of the object and can free type out the properties you need.
🌐
Tome's Land of IT
powertoe.wordpress.com › 2009 › 12 › 14 › powershell-part-4-arrays-and-for-loops
Powershell – Part 4 – Arrays and For Loops | Tome's Land of IT
July 8, 2011 - The foreach loop will set a variable to each item in a list with a much simpler construct: $array = @("test1", "test2", "test3") foreach ($element in $array) { $element }
🌐
Netwrix
netwrix.com › home › resources › blog › powershell foreach loop explained: syntax, examples and best practices | netwrix blog | insights for cybersecurity and it pros
PowerShell Foreach Loop Explained: Syntax, Examples and Best Practices – Netwrix Blog | Insights for Cybersecurity and IT Pros
August 25, 2025 - # Define an array of numbers $numbers = 1..5 # Loop through the array foreach ($number in $numbers) { Write-Host "Number (foreach keyword): $number" } The following PowerShell foreach example uses the Get-ChildItem cmdlet to retrieves the file from a specified directory and displays the name of each file:
Find elsewhere
🌐
Microsoft Learn
learn.microsoft.com › en-us › powershell › module › microsoft.powershell.core › about › about_foreach
about_Foreach - PowerShell | Microsoft Learn
January 19, 2026 - In this example, the $letterArray contains the string values a, b, c, and d. The first time the foreach statement runs, it sets the $letter variable equal to the first item in $letterArray (a). Then, it uses Write-Host to display the value. The next time through the loop, $letter is set to b. The pattern repeats for each item in the array.
🌐
Varonis
varonis.com › blog › powershell-array
PowerShell Array Guide: How to Use and Create
June 9, 2022 - For instance, to add a description to each item in our array, we can use this command: ... This command tells PowerShell to take the items in $data one at a time, and then for each of them add “Item: “ to the beginning, followed by the original value. There are several other ways to perform iterated actions in PowerShell, many of which will be familiar if you’ve used other programming languages: PowerShell includes ForEach ...
🌐
EDUCBA
educba.com › home › data science › data science tutorials › powershell tutorial › powershell loop through array
PowerShell Loop through Array | Guide to PowerShell Loop through Array
March 6, 2023 - Foreach-Object -Parallel loop with an array Syntax (Works with PowerShell 7).
Address   Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
PowerShell Forums
forums.powershell.org › powershell help
Using a Foreach loop with a single-object array - PowerShell Help - PowerShell Forums
January 31, 2016 - I use this function to input a string, search through every script module in my $pshome, and then offer up one or more finds for addition as an ISE script tab. Each function I write is a separate file with a name matching the function.
🌐
Xah Lee
xahlee.info › powershell › powershell_loop_array.html
PowerShell: Iterate Array
June 13, 2022 - ForEach is a hidden “intrinsic member” that PowerShell adds to every object.
🌐
Adam the Automator
adamtheautomator.com › powershell-foreach
PowerShell ForEach Loops: Types and Best Practices
The first type of foreach loop is a statement. foreach is an internal PowerShell keyword that’s not a cmdlet nor a function. The foreach statement is always used in the form: foreach ($i in $array).
Published   April 22, 2025
🌐
PDQ
pdq.com › blog › how-to-use-foreach-in-powershell
How to use Foreach in PowerShell | PDQ
October 9, 2025 - The best foreach option depends on your scenario: Use ForEach-Object for streaming pipeline data, the foreach keyword for fast in-memory loops, and .ForEach() for the fastest in-process operations on arrays/lists already in memory.
🌐
Ciraltos
ciraltos.com › home › blog › loop like a pro: powershell arrays & foreach tutorial for beginners
Loop Like a Pro: PowerShell Arrays & foreach Tutorial for Beginners - Ciraltos
October 12, 2025 - # Foreach example with array: foreach ($server in $servers) { Write-Host "Checking status of $server" } Sometimes, PowerShell returns a single object when you expect an array—especially when filtering results. That’s where the array subexpression operator @() comes in.
🌐
SharePoint Diary
sharepointdiary.com › sharepoint diary › powershell › how to loop through an array in powershell?
How to Loop through an Array in PowerShell? - SharePoint Diary
October 21, 2025 - The basic syntax for the foreach loop is as follows: ... # powershell loop thru array ForEach ($item in $array) { # Code to be executed for each item in the array }
🌐
DEV Community
dev.to › mjoycemilburn › ngsysv2-102-powershell-scripting-essentials-23cj
NgSysV2-10.2: PowerShell Scripting essentials - DEV Community
March 31, 2026 - ForEach loop — Designed for iterating through collections like arrays or output from commands.For example: $i = 0 # Initialise a counter while ($i -lt 5) { Write-Output "Iteration: $i" $i++ } Powershell's ...
🌐
SPGuides
spguides.com › powershell-loop-through-array
How to Loop Through an Array in PowerShell? – Learn SharePoint, Microsoft Power Platform and SPFx Tutorials – SPGuides
December 2, 2024 - In this example, the $users array is piped to the ForEach-Object cmdlet using the | character. The ForEach-Object cmdlet then executes the script block for each user in the array. The $_ variable represents the current element being processed in each iteration. Read Count the Number of Objects in an Array in PowerShell
🌐
SS64
ss64.com › ps › foreach-method.html
ForEach method - PowerShell cmdlet
ForEach-Object - Loop for each object in the pipeline (foreach) For - Loop through items that match a condition. IF - Conditionally perform a command. Switch - Multiple if statements. While - Loop while a condition is True. ForEach and Where magic methods by Kirk Munro.