1

For the upcoming Windows 10 Migration i need a list of MAC-addresses, IP-Addresses and computer name. Now we have lots of text files automaticly generated while users logon to the network. These text files contain the needed information. Now i want this information combined into one file.

This the the code so far.

$p = @("Physikalische Adresse . . . . . . :","IPv4-Adresse  . . . . . . . . . . :","Hostname  . . . . . . . . . . . . :")
Get-ChildItem d:\pc\ -Filter *.txt |Get-Content |Select-String -Pattern $p |

But the output gives something like this:

Hostname  . . . . . . . . . . . . : Computername
Physikalische Adresse . . . . . . : MAC-address
IPv4-Adresse  . . . . . . . . . . : IP-Address(Bevorzugt) 
Physikalische Adresse . . . . . . : 00-00-00-00-00-00-00-E0

But i would like this output:

Computername Mac-Address IP-Adress

The 00-00-00-00-00-00-00-E0 addresses should be filtered out, because those are the Tunneladapter, this information is not needed. It would be enough to have the output of one file in one Row, so i could filter using excel.

At this moment i have about 2000 text files.

Example of file content:

10681EU;KREIS;Vico;\\DSFW1 

Microsoft Windows [Version 6.1.7601]
Neue Verbindungen werden nicht gespeichert.


Status       Lokal     Remote                    Netzwerk

-------------------------------------------------------------------------------
OK           F:        \\i6633_nw\vol1\daten     Microsoft Windows Network
OK           J:        \\i6633_nw\vol1\prog      Microsoft Windows Network
OK           K:        \\keltenring1\vol1        Microsoft Windows Network
OK           N:        \\52.0.13.25\Kreisarchiv  Microsoft Windows Network
OK           O:        \\i4811_nw_gw\vol1        Microsoft Windows Network
OK           P:        \\giga\vol1               Microsoft Windows Network
Der Befehl wurde erfolgreich ausgefhrt.


Windows-IP-Konfiguration

   Hostname  . . . . . . . . . . . . : 10681EU
   Prim„res DNS-Suffix . . . . . . . : kreis.lan
   Knotentyp . . . . . . . . . . . . : Hybrid
   IP-Routing aktiviert  . . . . . . : Nein
   WINS-Proxy aktiviert  . . . . . . : Nein
   DNS-Suffixsuchliste . . . . . . . : kreis.lan

Ethernet-Adapter LAN-Verbindung:

   Verbindungsspezifisches DNS-Suffix: 
   Beschreibung. . . . . . . . . . . : Realtek PCIe GBE Family Controller
   Physikalische Adresse . . . . . . : 1C-6F-65-92-DE-06
   DHCP aktiviert. . . . . . . . . . : Nein
   Autokonfiguration aktiviert . . . : Ja
   IPv4-Adresse  . . . . . . . . . . : 52.0.103.215(Bevorzugt) 
   Subnetzmaske  . . . . . . . . . . : 255.255.0.0
   Standardgateway . . . . . . . . . : 52.0.1.1
   DNS-Server  . . . . . . . . . . . : 52.0.13.199
                                       52.0.13.200
   NetBIOS ber TCP/IP . . . . . . . : Aktiviert

Tunneladapter LAN-Verbindung* 9:

   Medienstatus. . . . . . . . . . . : Medium getrennt
   Verbindungsspezifisches DNS-Suffix: 
   Beschreibung. . . . . . . . . . . : Microsoft-6zu4-Adapter
   Physikalische Adresse . . . . . . : 00-00-00-00-00-00-00-E0
   DHCP aktiviert. . . . . . . . . . : Nein
   Autokonfiguration aktiviert . . . : Ja

Tunneladapter LAN-Verbindung* 11:

   Medienstatus. . . . . . . . . . . : Medium getrennt
   Verbindungsspezifisches DNS-Suffix: 
   Beschreibung. . . . . . . . . . . : Teredo Tunneling Pseudo-Interface
   Physikalische Adresse . . . . . . : 00-00-00-00-00-00-00-E0
   DHCP aktiviert. . . . . . . . . . : Nein
   Autokonfiguration aktiviert . . . : Ja
Roman78
  • 85
  • 3
  • 10

1 Answers1

0

You can use the following code to create an ArrayList of objects representing your data.

1) Create ArrayList that will hold the merged data from all files

2) Read files from directory using Get-ChildItem

3) Create a psobject with 3 properties + populate the properties with data using -notlike and -match operators.

Assumption: There is only 1 valid IP address/HostName/Physical Address per file.

$all = New-Object System.Collections.ArrayList

Get-ChildItem c:\temp\ -Filter *.txt | 
Foreach-Object {

    $content = Get-Content $_.FullName

    $obj = New-Object -TypeName psobject 
    $obj | Add-Member -MemberType NoteProperty -Name PhysicalAddress -Value ($content | where-object {($_ -notlike "*00-00-00-00-00*" -and $_ –match "Physikalische Adresse")} | foreach-object{$_.Split(":")[1].Trim()} | Select -First 1)
    $obj | Add-Member -MemberType NoteProperty -Name Hostname -Value ($content | where-object {($_ –match "HostName")} | foreach-object{$_.Split(":")[1].Trim()} | Select -First 1)
    $obj | Add-Member -MemberType NoteProperty -Name IPAddress -Value ($content | where-object {($_ –match "IPv4-Adresse")} | foreach-object{$_.Split(":")[1].Trim()} | Select -First 1)
    $all.Add($obj)
}

$all | Format-List

Output (array of):

PhysicalAddress : 1C-6F-65-92-DE-06
Hostname        : 10681EU
IPAddress       : 52.0.103.215
EylM
  • 5,967
  • 2
  • 16
  • 28