Public/Exos/Get-ExosLogConfig.ps1
function Get-ExosLogConfig { [CmdletBinding(DefaultParametersetName = "path")] Param ( [Parameter(Mandatory = $True, Position = 0, ParameterSetName = 'path')] [string]$ConfigPath, [Parameter(Mandatory = $True, Position = 0, ParameterSetName = 'array')] [array]$ConfigArray ) # It's nice to be able to see what cmdlet is throwing output isn't it? $VerbosePrefix = "Get-ExosLogConfig:" # Check for path and import if ($ConfigPath) { if (Test-Path $ConfigPath) { $LoopArray = Get-Content $ConfigPath } } else { $LoopArray = $ConfigArray } # Setup return Array $IpRx = [regex] "(\d+)\.(\d+)\.(\d+)\.(\d+)" $ReturnObject = @() $TotalLines = $LoopArray.Count $i = 0 $StopWatch = [System.Diagnostics.Stopwatch]::StartNew() # used by Write-Progress so it doesn't slow the whole function down # The following Rx will be ignored $IgnoreRx = @( '^#$' ) :fileloop foreach ($entry in $LoopArray) { $i++ # Write progress bar, we're only updating every 1000ms, if we do it every line it takes forever if ($StopWatch.Elapsed.TotalMilliseconds -ge 1000) { $PercentComplete = [math]::truncate($i / $TotalLines * 100) Write-Progress -Activity "$VerbosePrefix Reading Support Output" -Status "$PercentComplete% $i/$TotalLines" -PercentComplete $PercentComplete $StopWatch.Reset() $StopWatch.Start() } if ($entry -eq "") { continue } ########################################################################################### # Check for the Section $EvalParams = @{} $EvalParams.StringToEval = $entry.Trim() $EvalParams.Regex = [regex] "^#\ Module\ ems\ configuration" $Eval = Get-RegexMatch @EvalParams if ($Eval) { Write-Verbose "$VerbosePrefix $i`: ems: config started" $KeepGoing = $true continue } if ($KeepGoing) { # enable log target syslog <server>:<port> vr <vr> <facility> $EvalParams.Regex = [regex] '^enable\ log\ target\ syslog\ (?<server>.+?):\d+\ vr .+? .+' $Eval = Get-RegexMatch @EvalParams -ReturnGroupNumber 1 if ($Eval) { $ReturnObject += $Eval continue } # ignored lines foreach ($Rx in $IgnoreRx) { $EvalParams.Regex = [regex] $Rx $Eval = Get-RegexMatch @EvalParams if ($Eval) { continue fileloop } } # lines not processed Write-Verbose "$VerbosePrefix $i`: $entry" # next config section $EvalParams.Regex = [regex] "^(#)\ " $Eval = Get-RegexMatch @EvalParams if ($Eval) { break fileloop } } } return $ReturnObject | Select-Object -Unique } |