Collecting information from TXT


I have created a small script that cleans an ARP cache and want only keep THE IP Adress and MAC adress, but it seem it does not working well for me. Im new into PS. Any expert there out that can help me?

Get-Content -Path $File | Foreach-Object {$_ -replace "VLAN ", ""} | Foreach-Object {$_ -replace "Interface ", ""} |Foreach-Object {$_ -replace "JOGG55 ", ""} |Foreach-Object {$_ -replace "JOG55 ", ""}| Foreach-Object {$_ -replace "Aging Type", ""}|

Select-String -Pattern "\b(?:\d{1,3}\.){3}\d{1,3}\b"


IP address MAC address VLAN Interface Aging Type
10.99.146. 44 000b-abe3-a2df 133 JOG55 30 D b49c-df53-ffbb 133 JOG55 45 D

The clean text is making everything harder.

The script should return semicolon separated list containing the MAC and IP adress only but i dont make it work :(. Would love some help.




First, this appears to be very similar:

Actually, the "clean text’ is an object, so it makes things easier. Powershell is very object oriented. Powershell cmdlets typically return and accept objects. You actually did the hard work to parse raw text into an object, now you can just use Export-CSV to create a csv.

Get-Content -Path $File | 
Foreach-Object {$_ -replace "VLAN |Interface |JOGG55 |JOG55 |Aging Type "} |
Select-String -Pattern "\b(?:\d{1,3}\.){3}\d{1,3}\b" |
Export-CSV -Path C:\ARCache_Log.csv -NoTypeInformation

Using -replace uses a regex pattern, so you can simplify it using a pipe to represent OR and the overload for not passing a replacement is to use ‘’ (e.g. nothing).

Thank you soooo much , but the hard part is to remove , The VLAN and their Numbers without destroying the IP numbers same with 30 D, i think i need fix the pattern better.

If you can post some example text that you are parsing, it will be easier to test the code and see what is going on.

IP address MAC address
10.99.146. 44 000b-abe3-a2df 133 30 D b49c-df53-ffbb 133 45 D

PS C:\WINDOWS\system32

Now this look good since i can build up the script for removing all VLans etc- but now the only problem is if i Replace “133”, 30 D etc the IP adresses will get mest up since im removing the 133 , this script will be used to collect Data.

I tried to make a line that removes all text and only keeps the mac Adress and IP .


# Remove 2 or more spaces then create object using array
(Get-Content $file) -replace '\s{2,}',' ' |
ForEach-Object {
$line = $_ -split '\s'
IPAddress = $line[0]
MACAddress = $line[1]
VLAN = $line[2]
Interface = $line[3]
AgingType = $line[-2..-1] -join ' '
} | Select-Object * -Skip 1 -ExcludeProperty VLAN
# Use this, if you don't need the last character of the 'AgingType'
(Get-Content $file) -replace '\s{2,}',',' |
ConvertFrom-Csv | Select-Object * -ExcludeProperty VLAN