Link to home
Start Free TrialLog in
Avatar of LouisSanchez
LouisSanchez

asked on

Powershell Script needed

I would like a script that does the following. Compare two text files and find duplicates. Then take the duplicates and try to ping them. If the address can't be resolved(only this case "Ping request could not find host $hostname") then output to file. I'm looking for the exact code, I'm pretty sure it's out there, just don't have the time right now and it's an easy 500 points.
SOLUTION
Avatar of bobalob
bobalob
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
oh, it *won't* add a host which just times out to the output.txt by the way...
ASKER CERTIFIED SOLUTION
Avatar of Chris Dent
Chris Dent
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

I forgot to add file output, if you redirect at the end it'll deal with that.

That is, add this after the last curly bracket:  > OutputFile.txt

Chris
Avatar of LouisSanchez
LouisSanchez

ASKER

I guess I need more of a merge of duplicates not just only duplicates. This is what I have. If one of you guys could spruce it up I'll be all set.

#delete
$NULL>test.txt

#Merge Files
$file = gc file1.txt
$file += gc file2.txt
$file=$file | sort | get-unique
$file | Out-File -file "merge.txt" -enc ASCII

Compare-Object $(Get-Content merge.txt) $(Get-Content merge.txt) -IncludeEqual | ForEach-Object {
  $Entry = $Null
  Try {
    $Entry = [Net.Dns]::GetHostEntry($_.InputObject)
  } Catch { }
  If (!$?) {
    "Ping request could not find host $($_.InputObject)"
    $_.InputObject>> test.txt
  }
  Write-Verbose "$($_.InputObject) : $($Entry.AddressList)"
  }

You mean you need a unique list of machines from both files?

Chris
Yes in other words merge, remove duplicates, process remaining machines.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial