I write powershell scripts and regex below to extract a block of text between the first line (Port Name Status Vlan Speed Type) and the last line (End Here)but it didn't work. If you have suggestion, please help! Thx
Running this script, it just returned the first line.
Function Find_Ports($String)
foreach ($File in $Files)
{
$Config = Get-Content $File
$Port = Select-String -Path $File -Pattern $String | Select -
ExpandProperty line | Select-Object -First 1
if($Port)
{
$Port
}
Else
{
Write-Host "no port"
}
}
Find_Ports " (smi)^Port\s.+Name\s.+Status\s.+Vlan\s.+Duplex\s.+Speed\sType\r\n.*End\Here$"
Below is the text file
Port Name Status Vlan Duplex Speed Type Gi1/1 disabled 1 auto auto 10/100/1000-TX Gi1/2 disabled 1 auto auto 10/100/1000-TX Gi1/3 disabled 1 auto auto 10/100/1000-TX Gi1/4 disabled 1 auto auto 10/100/1000-TX Gi1/5 disabled 1 auto auto 10/100/1000-TX Gi1/6 disabled 150 auto auto 10/100/1000-TX Po1 connected trunk a-full a-1000 End Here