Powershell remove inactive computers from csv list

I have a list of hosts/computers in a csv file that I use. lets say list.csv

Some of the computer names in the ‘host name’ column of the csv likely have not been logged into in a while so I want to remove all rows that contain an out of date computer record.

Using below I can get all computers in the domain that have not been logged into in 90 days -ish

I want however to take that list of computers retrieved from below and run them against list.csv, where where one of the computer names matches I want to delete the entire row(s) from list.csv.

Ive tried now for a while with other articles and import-csv etc. but cant crack it.


$list = Import-Csv “C:\list.csv”

Below supposed to get all computers that are inactive over 90 days then display all that is in $list minus the inactive machines

Search-AdAccount -ComputersOnly -AccountInactive -TimeSpan 90 | Where{ $_.Name -notin $list.‘host name’ }

Export results of Search-ADAccount to a csv file then compare the two files.

$list1 = Import-Csv .\list1.csv
$list2 = Import-Csv .\list2.csv

# Pass only the different objects
$difference = Compare-Object -ReferenceObject $list1 -DifferenceObject $list2 -Property Hostname -PassThru | 
Select-Object * -ExcludeProperty SideIndicator

$difference | Export-Csv .\list-difference.csv -NoTypeInformation