Welcome Forums General PowerShell Q&A Powershell remove inactive computers from csv list

Viewing 1 reply thread
  • Author
    Posts
    • #69297
      Participant
      Topics: 1
      Replies: 0
      Points: 0
      Rank: Member

      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.

      Thanks

      $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’ }

    • #69301
      Participant
      Topics: 5
      Replies: 290
      Points: 243
      Helping Hand
      Rank: Participant

      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
      
Viewing 1 reply thread
  • The topic ‘Powershell remove inactive computers from csv list’ is closed to new replies.