ozzestriker
Goto Top

Powershell TxT Auswertung

Hallo Admins,

ich habe eine Problem welches ich mit Powershell lösen möchte. Ich habe etliche LogFiles von Switchen welche die einzelnen Ports und entsprechend daran hängende Geräte anzeigen. (Anhang input1.txt; input2.txt)

Dieses Textfiles möchte ich gerne einlesen und als Ergebnis bräuchte ich folgende Werte in einer Tabelle:
Local Intf:
Port id:
System Name:
Serial number:

jetzt bin ich leider nicht so der Profi und hol mir aus dem Netzt nur Schnippsel aber mit Get-Content müsste ich die Datei doch rudimentär (zeilenbasiert einlesen können oder ) Nur wie hole ich mir dann die Daten raus und füge diese dann direkt in eine Tabelle ?

Für eure Hilfe wäre ich super dankbar !!


Anhang:
Local Intf: Gi1/0/40
Chassis id: 2XX.XXX.XXX.XXX
Port id: c81f.ea6c.611e
Port Description - not advertised
System Name: AVX6C611E
System Description - not advertised

Time remaining: 97 seconds
System Capabilities: B,T
Enabled Capabilities: B,T
Management Addresses:
IP: 2X.XX.XX.XXX
OID:
1.3.6.1.4.1.6889.1.69.2.7.
Auto Negotiation - not supported
Physical media capabilities - not advertised
Media Attachment Unit type: 30
Vlan ID: - not advertised

MED Information:

MED Codes:
(NP) Network Policy, (LI) Location Identification
(PS) Power Source Entity, (PD) Power Device
(IN) Inventory

H/W revision: 9608GD03B
S/W revision: 6.841D
Serial number: 17WZ50500585
Manufacturer: Avaya
Model: 9608
Capabilities: NP, PD, IN
Device type: Endpoint Class III
Network Policy(Voice): VLAN 72, tagged, Layer-2 priority: 5, DSCP: 46
Power requirements - not advertised
Location - not advertised

Local Intf: Gi1/0/26
Chassis id: 2XX.XXX.XXX.XXX
Port id: c81f.ea6c.6140
Port Description - not advertised
System Name: AVX6C6140
System Description - not advertised

Time remaining: 101 seconds
System Capabilities: B,T
Enabled Capabilities: B,T
Management Addresses:
IP: 2X.XXX.XXX.XXX
OID:
1.3.6.1.4.1.6889.1.69.2.7.
Auto Negotiation - not supported
Physical media capabilities - not advertised
Media Attachment Unit type: 30
Vlan ID: - not advertised

MED Information:

MED Codes:
(NP) Network Policy, (LI) Location Identification
(PS) Power Source Entity, (PD) Power Device
(IN) Inventory

H/W revision: 9608GD03B
S/W revision: 6.841D
Serial number: 17WZ5050059E
Manufacturer: Avaya
Model: 9608
Capabilities: NP, PD, IN
Device type: Endpoint Class III
Network Policy(Voice): VLAN 72, tagged, Layer-2 priority: 5, DSCP: 46
Power requirements - not advertised
Location - not advertised

Content-Key: 7802829270

Url: https://administrator.de/contentid/7802829270

Printed on: April 28, 2024 at 06:04 o'clock

Member: TK1987
TK1987 Jul 10, 2023 at 09:43:43 (UTC)
Goto Top
Moin,

$Root = "C:\Quellpfad"  

$Tabelle = Foreach ($TxtFile in Get-ChildItem "$Root\*.txt") {  
  $Content = Get-Content $TxtFile
  [PsCustomObject][ordered]@{
    "Local Intf"    = $Content | Where {$_ -Like "Local Intf:*"   } | Foreach {$_.Split(":",2)[1].TrimStart()}  
    "Port id"       = $Content | Where {$_ -Like "Port id:*"      } | Foreach {$_.Split(":",2)[1].TrimStart()}  
    "System Name"   = $Content | Where {$_ -Like "System Name:*"  } | Foreach {$_.Split(":",2)[1].TrimStart()}  
    "Serial number" = $Content | Where {$_ -Like "Serial number:*"} | Foreach {$_.Split(":",2)[1].TrimStart()}  
  }
}
$Tabelle

Gruß Thomas
Member: Kraemer
Kraemer Jul 10, 2023 at 09:49:43 (UTC)
Goto Top
Ich würde das ja mit einem Regex lösen:

$a -match "(?ms)Local Intf: ([\w/]+).*Port id: ([a-zA-Z0-9.]+).*System Name: ([a-zA-Z0-9]+).*Serial number: ([a-zA-Z0-9]+)"  
Member: Ozzestriker
Ozzestriker Jul 10, 2023 at 09:55:29 (UTC)
Goto Top
Hi vielen Dank für die schnelle Hilfe. Habs anhand meines Beispiels durchgespielt bekomme folgendes Ergebnis sieh Bild.

Einerseits wäre schön wenn die einzelnen gefundenen Ergebnisse/Treffer untereinander in der Tabelle angezeigt werden würden und Serial Number findet er nichts obwohl diese drin steht.
ergebnis
Member: TK1987
TK1987 Jul 10, 2023 at 09:57:20 (UTC)
Goto Top
Zitat von @Kraemer:
Ich würde das ja mit einem Regex lösen:

$a -match "(?ms)Local Intf: ([\w/]+).*Port id: ([a-zA-Z0-9.]+).*System Name: ([a-zA-Z0-9]+).*Serial number: ([a-zA-Z0-9]+)"  
Dann hat man die Werte aber nicht in einer Tabelle.

BTW: Du hast die pipes im Regex vergessen.

Gruß Thomas
Member: Kraemer
Kraemer Jul 10, 2023 at 10:00:19 (UTC)
Goto Top
Zitat von @TK1987:

BTW: Du hast die pipes im Regex vergessen.
das Regex funktioniert einwandfrei!
Member: TK1987
TK1987 Jul 10, 2023 at 10:01:56 (UTC)
Goto Top
Zitat von @Ozzestriker:
Hi vielen Dank für die schnelle Hilfe. Habs anhand meines Beispiels durchgespielt bekomme folgendes Ergebnis sieh Bild.
Also ich bekomme mit deinen Anhängen folgendes Ergebnis:
screenshot

Bitte überprüfe mal die Textkodierung.

Gruß Thomas
Mitglied: 7426148943
7426148943 Jul 10, 2023 updated at 13:30:15 (UTC)
Goto Top
[regex]::matches((Get-Content *.txt -raw | out-string),'(?ism)^Local Intf:\s*([^\r\n]*).*?^Port id:\s*([^\r\n]*).*?^System Name:\s*([^\r\n]*).*?^Serial number:\s*([^\r\n]*)').Captures | %{  
    [pscustomobject]@{
        'Local Intf' = $_.Groups[1].Value  
        'Port Id' = $_.Groups[2].Value  
        'System Name' = $_.Groups[3].Value  
        'Serial Number' = $_.Groups[4].Value  
    }
}
https://tio.run/##7VNdb9NAEHy/X7EPoNpVcrXTxE0sIRriqFhqg6VAiOgHutqb5MD2mb ...
Member: Ozzestriker
Ozzestriker Jul 10, 2023 at 10:02:09 (UTC)
Goto Top
Sorry bin überfordert wie würde ich den die Lösung mit dem Regex anwenden ?
Member: aqui
aqui Jul 10, 2023 updated at 11:53:42 (UTC)
Goto Top
Der Klick auf:
https://tio.run/##7VNdb9NAEHy/X7EPoNpVcrXTxE0sIRriqFhqg6VAiOgHutqb5MD2mb ...
macht doch genau das was du willst!
Wo ist also dein wirkliches Problem? 🤔
Member: Ozzestriker
Ozzestriker Jul 10, 2023 at 12:11:50 (UTC)
Goto Top
Und wie bekomme ich das jetzt am besten für 20 txt files automatisiert ?
Member: Kraemer
Kraemer Jul 10, 2023 at 12:14:05 (UTC)
Goto Top
Zitat von @Ozzestriker:

Und wie bekomme ich das jetzt am besten für 20 txt files automatisiert ?

Wieso testest du den Code nicht einfach mal?
Member: Ozzestriker
Ozzestriker Jul 10, 2023 at 12:20:41 (UTC)
Goto Top
Ich habs getestet aber wenn ich zwei Textfiles im Verzeichnis habe nimmt der Code das erst Textfile.
Das zweite lässt er links liegen.

Oder hab ich noch einen FehleR ?
Member: TK1987
TK1987 Jul 10, 2023 updated at 12:28:41 (UTC)
Goto Top
Zitat von @Ozzestriker:
Ich habs getestet aber wenn ich zwei Textfiles im Verzeichnis habe nimmt der Code das erst Textfile.
Das zweite lässt er links liegen.
Ersetze Zeile 1 durch
[regex]::matches("$(Get-Content *.txt -raw)",'(?ism)^Local Intf:\s*([^\r\n]*).*?^Port id:\s*([^\r\n]*).*?^System Name:\s*([^\r\n]*).*?^Serial number:\s*([^\r\n]*)').Captures | %{   
dann sollte es funktionieren.

Gruß Thomas
Member: Kraemer
Kraemer Jul 10, 2023 updated at 12:37:13 (UTC)
Goto Top
Zitat von @TK1987:

Ersetze Zeile 1 durch
[regex]::matches("$(Get-Content *.txt -raw)",'(?ism)^Local Intf:\s*([^\r\n]*).*?^Port id:\s*([^\r\n]*).*?^System Name:\s*([^\r\n]*).*?^Serial number:\s*([^\r\n]*)').Captures | %{   
dann sollte es funktionieren.
nope

aber das
[regex]::matches((Get-Content *.txt -raw),'(?ism)Local Intf:\s*([^\r\n]*).*?^Port id:\s*([^\r\n]*).*?^System Name:\s*([^\r\n]*).*?^Serial number:\s*([^\r\n]*)').Captures | %{    
    [pscustomobject]@{
        'Local Intf' = $_.Groups[1].Value    
        'Port Id' = $_.Groups[2].Value    
        'System Name' = $_.Groups[3].Value    
        'Serial Number' = $_.Groups[4].Value    
    }
}


https://tio.run/##7VXvb5tIEP2@f8V8uJMhsgn4B7GRqsY1VoqU@JDcc61L0moDY3t7wN ...
Member: Ozzestriker
Ozzestriker Jul 10, 2023 at 12:35:43 (UTC)
Goto Top
Ich bin echt zu doof.

Das ist was ich im Moment im Verzeichnis in dem auch die Txt Dateien sind ausführe:
[regex]::matches("$(Get-Content *.txt -raw)",'(?ism)^Local Intf:\s*([^\r\n]*).*?^Port id:\s*([^\r\n]*).*?^System Name:\s*([^\r\n]*).*?^Serial number:\s*([^\r\n]*)').Captures | %{     
    [pscustomobject]@{
        LocalIntf = $_.Groups[1].Value
        PortId = $_.Groups[2].Value
        SystemName = $_.Groups[3].Value
        SerialNumber = $_.Groups[4].Value
    }
}

Wenn ich das mache bekomme ich einen Fehler
Es ist nicht möglich, einen Index auf ein NULL-Array anzuwenden.
In Zeile:2 Zeichen:5
+     [pscustomobject]@{
+     ~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : NullArray
Mitglied: 7426148943
7426148943 Jul 10, 2023 updated at 13:40:35 (UTC)
Goto Top
Och mönsch, einfach nur den Pfad und Dateifilter ersetzen ..
Get-Content "d:\ordner\*.txt" -raw  
Ergibt
[regex]::matches((Get-Content "d:\ordner\*.txt" -raw | out-string),'(?ism)^Local Intf:\s*([^\r\n]*).*?^Port id:\s*([^\r\n]*).*?^System Name:\s*([^\r\n]*).*?^Serial number:\s*([^\r\n]*)').Captures | %{    
    [pscustomobject]@{
        'Local Intf' = $_.Groups[1].Value    
        'Port Id' = $_.Groups[2].Value    
        'System Name' = $_.Groups[3].Value    
        'Serial Number' = $_.Groups[4].Value    
    }
}
Member: Kraemer
Kraemer Jul 10, 2023 at 13:27:42 (UTC)
Goto Top
Zitat von @7426148943:

[regex]::matches((Get-Content "d:\ordner\*.txt" -raw),'(?ism)^Local Intf:\s*([^\r\n]*).*?^Port id:\s*([^\r\n]*).*?^System


Das ^ nach (?ism) muss aber trotzdem raus....
Mitglied: 7426148943
7426148943 Jul 10, 2023 updated at 13:29:27 (UTC)
Goto Top
Zitat von @Kraemer:

Zitat von @7426148943:

[regex]::matches((Get-Content "d:\ordner\*.txt" -raw),'(?ism)^Local Intf:\s*([^\r\n]*).*?^Port id:\s*([^\r\n]*).*?^System


Das ^ nach (?ism) muss aber trotzdem raus....

Nö solange der Text immer am Zeilenanfang steht nicht.
Member: Kraemer
Kraemer Jul 10, 2023 at 13:30:01 (UTC)
Goto Top
Zitat von @7426148943:

Zitat von @Kraemer:

Zitat von @7426148943:

[regex]::matches((Get-Content "d:\ordner\*.txt" -raw),'(?ism)^Local Intf:\s*([^\r\n]*).*?^Port id:\s*([^\r\n]*).*?^System


Das ^ nach (?ism) muss aber trotzdem raus....

Nö solange der Text immer am Zeilenanfang steht nicht.

probiere es selbst: https://tio.run/##7VXvb5tIEP2@f8V8uJMhsgn4B7GRqsY1VoqU@JDcc61L0moDY3t7wN ...
Mitglied: 7426148943
7426148943 Jul 10, 2023 at 13:33:58 (UTC)
Goto Top
Du nutzt ja noch die alte Variante ...
Member: Kraemer
Kraemer Jul 10, 2023 updated at 13:40:34 (UTC)
Goto Top
Zitat von @7426148943:

Ihr nutzt ja noch die alte Variante ...

oh wie witzig - aber ja, mit deiner versteckten Änderung funktioniert es auch
Member: Ozzestriker
Ozzestriker Jul 10, 2023 at 14:04:51 (UTC)
Goto Top
Also egal was ich mach ich bekomm es nicht hin sorry ! Bin am verzweifeln.

Ich hab unter C:\Testfile\input.txt liegen

und folgenden Code Verwende ich:

[regex]::matches((Get-Content "C:\Testfile\*.txt" -raw | out-string),'(?ism)^Local Intf:\s*([^\r\n]*).*?^Port id:\s*([^\r\n]*).*?^System Name:\s*([^\r\n]*).*?^Serial number:\s*([^\r\n]*)').Captures | %{      
    [pscustomobject]@{
        'Local Intf' = $_.Groups[1].Value      
        'Port Id' = $_.Groups[2].Value      
        'System Name' = $_.Groups[3].Value      
        'Serial Number' = $_.Groups[4].Value      
    }
}

folgendes Ergebnis kommt dabei raus:

PS C:\WINDOWS\system32> T:\Abteilungen\OE410\0000\Admins\Horter\Anwendungen\Powershell\Powershell_Log auswertung\Unbenannt9.ps1
Es ist nicht möglich, einen Index auf ein NULL-Array anzuwenden.
In T:\Abteilungen\OE410\0000\Admins\Horter\Anwendungen\Powershell\Powershell_Log auswertung\Unbenannt9.ps1:2 Zeichen:5
+     [pscustomobject]@{
+     ~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : NullArray
 
Member: Kraemer
Kraemer Jul 10, 2023 at 14:13:08 (UTC)
Goto Top
Dann hat deine Testdatei nicht den oben gezeigen Inhalt oder es stimmt was mit der Codierung der Datei nicht. Linuxzeilenende?
Member: Ozzestriker
Ozzestriker Jul 11, 2023 at 05:49:15 (UTC)
Goto Top
Also was kann ich noch machen ?

Bei euch funktioniert es und bei mir nicht wo mach ich den Fehler ?

Ich habe nochmal den Inhalt der Textdatei angefügt welche auf meinem Verzeichnis C:\Test\input.txt liegt.

Als Code habe ich genau das von euch kopiert und den Pfad angepasst. Außer euren Code lasse ich vorher nichts laufen. und trotzdem bekomme ich diese Meldung.

------------------------------------------------
Local Intf: Gi1/0/40
Chassis id: 2XX.XXX.XXX.XXX
Port id: c81f.ea6c.611e
Port Description - not advertised
System Name: AVX6C611E
System Description - not advertised

Time remaining: 97 seconds
System Capabilities: B,T
Enabled Capabilities: B,T
Management Addresses:
    IP: 2X.XX.XX.XXX
    OID:
        1.3.6.1.4.1.6889.1.69.2.7.
Auto Negotiation - not supported
Physical media capabilities - not advertised
Media Attachment Unit type: 30
Vlan ID: - not advertised

MED Information:

    MED Codes:
          (NP) Network Policy, (LI) Location Identification
          (PS) Power Source Entity, (PD) Power Device
          (IN) Inventory

    H/W revision: 9608GD03B
    S/W revision: 6.841D
    Serial number: 17WZ50500585
    Manufacturer: Avaya
    Model: 9608
    Capabilities: NP, PD, IN
    Device type: Endpoint Class III
    Network Policy(Voice): VLAN 72, tagged, Layer-2 priority: 5, DSCP: 46
    Power requirements - not advertised
    Location - not advertised

------------------------------------------------
Local Intf: Gi1/0/26
Chassis id: 2XX.XXX.XXX.XXX
Port id: c81f.ea6c.6140
Port Description - not advertised
System Name: AVX6C6140
System Description - not advertised

Time remaining: 101 seconds
System Capabilities: B,T
Enabled Capabilities: B,T
Management Addresses:
    IP: 2X.XXX.XXX.XXX
    OID:
        1.3.6.1.4.1.6889.1.69.2.7.
Auto Negotiation - not supported
Physical media capabilities - not advertised
Media Attachment Unit type: 30
Vlan ID: - not advertised

MED Information:

    MED Codes:
          (NP) Network Policy, (LI) Location Identification
          (PS) Power Source Entity, (PD) Power Device
          (IN) Inventory

    H/W revision: 9608GD03B
    S/W revision: 6.841D
    Serial number: 17WZ5050059E
    Manufacturer: Avaya
    Model: 9608
    Capabilities: NP, PD, IN
    Device type: Endpoint Class III
    Network Policy(Voice): VLAN 72, tagged, Layer-2 priority: 5, DSCP: 46
    Power requirements - not advertised
    Location - not advertised

------------------------------------------------


[regex]::matches((Get-Content "C:\Testfile\*.txt" -raw | out-string),'(?ism)^Local Intf:\s*([^\r\n]*).*?^Port id:\s*([^\r\n]*).*?^System Name:\s*([^\r\n]*).*?^Serial number:\s*([^\r\n]*)').Captures | %{        
    [pscustomobject]@{
        'Local Intf' = $_.Groups[1].Value        
        'Port Id' = $_.Groups[2].Value        
        'System Name' = $_.Groups[3].Value        
        'Serial Number' = $_.Groups[4].Value        
    }
}
Member: Ozzestriker
Ozzestriker Jul 11, 2023 at 05:54:21 (UTC)
Goto Top
Vielleicht noch zur Info oder Fehleranalyse:

Wenn ich folgendes als Code eingebe funktioniert alles super:

@'  
Local Intf: Gi1/0/40
Chassis id: 2XX.XXX.XXX.XXX
Port id: c81f.ea6c.611e
Port Description - not advertised
System Name: AVX6C611E
System Description - not advertised

Time remaining: 97 seconds
System Capabilities: B,T
Enabled Capabilities: B,T
Management Addresses:
IP: 2X.XX.XX.XXX
OID:
1.3.6.1.4.1.6889.1.69.2.7.
Auto Negotiation - not supported
Physical media capabilities - not advertised
Media Attachment Unit type: 30
Vlan ID: - not advertised

MED Information:

MED Codes:
(NP) Network Policy, (LI) Location Identification
(PS) Power Source Entity, (PD) Power Device
(IN) Inventory

H/W revision: 9608GD03B
S/W revision: 6.841D
Serial number: 17WZ50500585
Manufacturer: Avaya
Model: 9608
Capabilities: NP, PD, IN
Device type: Endpoint Class III
Network Policy(Voice): VLAN 72, tagged, Layer-2 priority: 5, DSCP: 46
Power requirements - not advertised
Location - not advertised
'@ | out-file test3.txt  
@'  
Local Intf: Gi1/0/26
Chassis id: 2XX.XXX.XXX.XXX
Port id: c81f.ea6c.6140
Port Description - not advertised
System Name: AVX6C6140
System Description - not advertised

Time remaining: 101 seconds
System Capabilities: B,T
Enabled Capabilities: B,T
Management Addresses:
IP: 2X.XXX.XXX.XXX
OID:
1.3.6.1.4.1.6889.1.69.2.7.
Auto Negotiation - not supported
Physical media capabilities - not advertised
Media Attachment Unit type: 30
Vlan ID: - not advertised

MED Information:

MED Codes:
(NP) Network Policy, (LI) Location Identification
(PS) Power Source Entity, (PD) Power Device
(IN) Inventory

H/W revision: 9608GD03B
S/W revision: 6.841D
Serial number: 17WZ5050059E
Manufacturer: Avaya
Model: 9608
Capabilities: NP, PD, IN
Device type: Endpoint Class III
Network Policy(Voice): VLAN 72, tagged, Layer-2 priority: 5, DSCP: 46
Power requirements - not advertised
Location - not advertised
'@ | out-file test4.txt  
@'  
Local Intf: Gi1/0/40
Chassis id: 2XX.XXX.XXX.XXX
Port id: c81f.ea6c.611e
Port Description - not advertised
System Name: AVX6C611E
System Description - not advertised

Time remaining: 97 seconds
System Capabilities: B,T
Enabled Capabilities: B,T
Management Addresses:
IP: 2X.XX.XX.XXX
OID:
1.3.6.1.4.1.6889.1.69.2.7.
Auto Negotiation - not supported
Physical media capabilities - not advertised
Media Attachment Unit type: 30
Vlan ID: - not advertised

MED Information:

MED Codes:
(NP) Network Policy, (LI) Location Identification
(PS) Power Source Entity, (PD) Power Device
(IN) Inventory

H/W revision: 9608GD03B
S/W revision: 6.841D
Serial number: 17WZ50500585
Manufacturer: Avaya
Model: 9608
Capabilities: NP, PD, IN
Device type: Endpoint Class III
Network Policy(Voice): VLAN 72, tagged, Layer-2 priority: 5, DSCP: 46
Power requirements - not advertised
Location - not advertised
'@ | out-file test2.txt  
@'  
Local Intf: Gi1/0/26
Chassis id: 2XX.XXX.XXX.XXX
Port id: c81f.ea6c.6140
Port Description - not advertised
System Name: AVX6C6140
System Description - not advertised

Time remaining: 101 seconds
System Capabilities: B,T
Enabled Capabilities: B,T
Management Addresses:
IP: 2X.XXX.XXX.XXX
OID:
1.3.6.1.4.1.6889.1.69.2.7.
Auto Negotiation - not supported
Physical media capabilities - not advertised
Media Attachment Unit type: 30
Vlan ID: - not advertised

MED Information:

MED Codes:
(NP) Network Policy, (LI) Location Identification
(PS) Power Source Entity, (PD) Power Device
(IN) Inventory

H/W revision: 9608GD03B
S/W revision: 6.841D
Serial number: 17WZ5050059E
Manufacturer: Avaya
Model: 9608
Capabilities: NP, PD, IN
Device type: Endpoint Class III
Network Policy(Voice): VLAN 72, tagged, Layer-2 priority: 5, DSCP: 46
Power requirements - not advertised
Location - not advertised
'@ | out-file test.txt  

[regex]::matches((Get-Content *.txt -raw),'(?ism)Local Intf:\s*([^\r\n]*).*?^Port id:\s*([^\r\n]*).*?^System Name:\s*([^\r\n]*).*?^Serial number:\s*([^\r\n]*)').Captures | %{    
    [pscustomobject]@{
        'Local Intf' = $_.Groups[1].Value    
        'Port Id' = $_.Groups[2].Value    
        'System Name' = $_.Groups[3].Value    
        'Serial Number' = $_.Groups[4].Value    
    }
}
Mitglied: 7426148943
Solution 7426148943 Jul 11, 2023 updated at 05:59:24 (UTC)
Goto Top
In dem Fall steht "Serial number:" nicht am Anfang der Zeile, deswegen klappt es bei dir nicht,..ein Caret weg und das wars:
[regex]::matches((Get-Content "C:\Testfile\*.txt" -raw | out-string),'(?ism)^Local Intf:\s*([^\r\n]*).*?^Port id:\s*([^\r\n]*).*?^System Name:\s*([^\r\n]*).*?Serial number:\s*([^\r\n]*)').Captures | %{          
    [pscustomobject]@{
        'Local Intf' = $_.Groups[1].Value          
        'Port Id' = $_.Groups[2].Value          
        'System Name' = $_.Groups[3].Value          
        'Serial Number' = $_.Groups[4].Value          
    }
}

Regex Tutorial
Member: Ozzestriker
Ozzestriker Jul 11, 2023 at 06:09:14 (UTC)
Goto Top
Ok nach ein bissel Testen habe ich den Fehler gefunden es hat anscheinend damit zu tun das meine Datei

oben eine Zeile hat mit ------------------------------------------------

die ist in euren Beispielen nicht drin.

Könntet ihr bitte nochmal schauen mit folgendem Input File
=~=~=~=~=~=~=~=~=~=~=~= PuTTY log 2023.05.22 10:41:20 =~=~=~=~=~=~=~=~=~=~=~=
login as: XXXXXXXXX
Keyboard-interactive authentication prompts from server:
| AD password: 
End of keyboard-interactive prompts from server

-------------------------------------------------------
             XXXXXXXXXXXXXXXXXXXXXXXXXXXX
             XXXXXXXXXXXXXXXXXXXXXXXxXXXX
                      XXXXXXXXXXXXXXX
               Verteiler DV-BT3-2.OG / C-02-08c
      Access-Switch - Cisco Catalyst XXXXXXXXXXXXXXXx
                      XXXXXXXXXXXXXXXXXX
-------------------------------------------------------
             Unerlaubter Zugriff verboten!
            Unauthorized access prohibited!
-------------------------------------------------------HS-296X-08#term len 0
HS-296X-08#sh lldp neigh deta
------------------------------------------------
Local Intf: Gi1/0/40
Chassis id: X
Port id: c81f.ea6c.611e
Port Description - not advertised
System Name: AVX6C611E
System Description - not advertised

Time remaining: 97 seconds
System Capabilities: B,T
Enabled Capabilities: B,T
Management Addresses:
    IP: X
    OID:
        1.3.6.1.4.1.6889.1.69.2.7.
Auto Negotiation - not supported
Physical media capabilities - not advertised
Media Attachment Unit type: 30
Vlan ID: - not advertised

MED Information:

    MED Codes:
          (NP) Network Policy, (LI) Location Identification
          (PS) Power Source Entity, (PD) Power Device
          (IN) Inventory

    H/W revision: 9608GD03B
    S/W revision: 6.841D
    Serial number: 17WZ50500585
    Manufacturer: Avaya
    Model: 9608
    Capabilities: NP, PD, IN
    Device type: Endpoint Class III
    Network Policy(Voice): VLAN 72, tagged, Layer-2 priority: 5, DSCP: 46
    Power requirements - not advertised
    Location - not advertised

------------------------------------------------
Local Intf: Gi1/0/26
Chassis id: X
Port id: c81f.ea6c.6140
Port Description - not advertised
System Name: AVX6C6140
System Description - not advertised

Time remaining: 101 seconds
System Capabilities: B,T
Enabled Capabilities: B,T
Management Addresses:
    IP: X
    OID:
        1.3.6.1.4.1.6889.1.69.2.7.
Auto Negotiation - not supported
Physical media capabilities - not advertised
Media Attachment Unit type: 30
Vlan ID: - not advertised

MED Information:

    MED Codes:
          (NP) Network Policy, (LI) Location Identification
          (PS) Power Source Entity, (PD) Power Device
          (IN) Inventory

    H/W revision: 9608GD03B
    S/W revision: 6.841D
    Serial number: 17WZ5050059E
    Manufacturer: Avaya
    Model: 9608
    Capabilities: NP, PD, IN
    Device type: Endpoint Class III
    Network Policy(Voice): VLAN 72, tagged, Layer-2 priority: 5, DSCP: 46
    Power requirements - not advertised
    Location - not advertised

------------------------------------------------


Total entries displayed: 2

HS-296X-08#exit
Member: Ozzestriker
Ozzestriker Jul 11, 2023 at 06:19:21 (UTC)
Goto Top
Vielen Dank für eure Hilfe und eure Geduld mit mir !