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 $edu.name -Count 2 -Quiet)) { write-warning "$($edu.Name) is not online. Removing from list." # This is where I want to remove from list continue } } pause # to see which computers are not online $education
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!