ForEach loop to remove item in list gathered from Get-ADComputer

Hello all -

I am newer to PowerShell and am writing a script to help with some things at my employer.
I am familiar enough with code logic, but can’t seem to find the resource I need. What I am trying to do is iterate through an array pulled from my AD. Below is what I am trying to accomplish - not even sure if it’s possible the way I am trying to do it.

# Get computers in Education department
$education = Get-ADComputer -Filter {enabled -eq $true -and Name -like "EDU-*"} -Properties * | Sort Name | Select Name, OperatingSystem, LastLogonDate

That should create an array in the variable $education (which it does).

foreach($edu in $education) {
     if (-not( Test-Connection -ComputerName $ -Count 2 -Quiet)) {
          write-warning "$($edu.Name) is not online. Removing from list."
          # This is where I want to remove from list
pause # to see which computers are not online

My thoughts are that I should be able to remove items dynamically from the $education array while it loops through - but I am not sure if I am going about it correctly.
I appreciate the help in advance!

How about:

$newlist = foreach ($edu in $education) {
  if (Test-Connection -ComputerName $ -Count 2 -Quiet) {


$newlist = $edu | where { Test-Connection -ComputerName $ -Count 2 -Quiet }

js -


Both of those work great.

I have 12 departments I have to iterate through, so this will help a lot. Appreciate it again!