Asked by:
Powershell - Read list of IP addresses from file and find matches in Get-NetNeighbor

Question
-
Hi
I'm putting together a PowerShell script to:
1) Read in a list of IP address from a CSV (or TXT) file
2) Get the local machines ARP table using Get-NetNeighbor
3) Compare the IP addresses in the text file against the Get-NetNeighbor result
4) Save the IP's that match into local variables
I'm new to PowerShell so am still reading up on things but any advise or help with an example would be very much appreciated.
Many thanks
Tuesday, January 16, 2018 1:29 PM
All replies
-
Tuesday, January 16, 2018 2:32 PM
-
My mistake. Thanks for the links to the other forums.
Tuesday, January 16, 2018 3:40 PM -
Hi William,
Based on my research, I will give you the following recommendations. Hope it is helpful to you:
>> 1) Read in a list of IP address from a CSV (or TXT) file
You can use Import-Csv (CSV) or Get-Content (TXT) for importing data to the PowerShell Console. In this case, I recommend using CSV.
>> 2) Get the local machines ARP table using Get-NetNeighbor
You can use (Get-NetNeighbor).IPAddress to get the IPAddress information in the ARP table.
>> 3) Compare the IP addresses in the text file against the Get-NetNeighbor result
You can use Compare-Object to compare two objects.
>> 4) Save the IP's that match into local variables
Here is the demo script, hope it is helpful to you:
$csvData = (Import-Csv -Path D:\IPAddress.csv).IPAddress $arpData = (Get-NetNeighbor).IPAddress $compareResult = Compare-Object -ReferenceObject $arpData -DifferenceObject $csvData -IncludeEqual -ExcludeDifferent $compareResult
If you need further help, please feel free to let us know.
Best Regards,
Albert
Please remember to mark the replies as an answers if they help.
If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com- Edited by Albert LingMicrosoft contingent staff Wednesday, January 17, 2018 5:56 AM
- Proposed as answer by Albert LingMicrosoft contingent staff Tuesday, January 23, 2018 5:51 AM
Wednesday, January 17, 2018 5:52 AM -
Hi,
Just checking in to see if the information provided was helpful.
Please let us know if you would like further assistance.
Best Regards,
AlbertPlease remember to mark the replies as an answers if they help.
If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.comFriday, January 19, 2018 2:37 AM -
Hi,
I am checking how the issue is going, if you still have any questions, please feel free to contact us.
If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.
If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.
If no, please reply and tell us the current situation in order to provide further help.
Appreciate for your feedback.
Best Regards,
AlbertPlease remember to mark the replies as an answers if they help.
If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.comTuesday, January 23, 2018 5:51 AM