Skip to content

Instantly share code, notes, and snippets.

@jrich523
Created September 18, 2015 01:16
Show Gist options
  • Save jrich523/3bd68764fd70bb091232 to your computer and use it in GitHub Desktop.
Save jrich523/3bd68764fd70bb091232 to your computer and use it in GitHub Desktop.
$rawVirtual = $rawLTM | ? h1 -eq "virtual"
$virtualData = $rawVirtual | %{
#$body = $_.body -split "\n"
$body = $_.body |?{$_ -match '(?ms)^(\S+.+?)\{(.+)\}' }|%{$Matches[2]}
$persist,$profiles,$rules,$address,$port = $null
#persist
$persist = $body |?{$_ -match "(?s)\s+persist\s+\{(.+?)\}.\s+\b"} | %{$matches[1]}
#profiles
$profiles = $body |?{$_ -match "(?s)\s+profiles\s+\{(.+?)\}.\s+\b"} | %{$matches[1]}
#rules
$rules = $body |?{$_ -match "(?s)\s+rules\s+\{(.+?)\}.\s+\b"} | %{$matches[1].trim()}
#destination
$address,$port = $body |?{$_ -match "\s+destination\s+/Common/(.+)"} | %{$matches[1].trim() -split":"}
[pscustomobject]@{
Entity = $_.H2
Address = $address
Port = $port
Protocol = $body | ? {$_ -match "ip-protocol (.+)"} | %{$Matches[1]}
Mask = $body | ? {$_ -match "mask (.+)"} | %{$Matches[1]}
Pool = $body | ? {$_ -match "pool (.+)"} | %{$Matches[1]}
Source = $body | ? {$_ -match "source (.+)"} | %{$Matches[1]}
translateAddress = $body | ? {$_ -match "translate-address (.+)"} | %{$Matches[1]}
translatePort = $body | ? {$_ -match "translate-port (.+)"} | %{$Matches[1]}
Persist = $persist -replace '[\n\r]|\s{2,}',''
Profiles = $profiles -replace '(?ms)^\s+|\{ \}','' -replace "\{\n(.+)\n\}",'{$1}' -replace "\s*\n",";"
Rules = ($rules -split "\n" | %{$_.trim()}) -join ";"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment