Last active
May 31, 2023 16:52
-
-
Save joel74/bfc4beb79d4030b52552cced52535e0a to your computer and use it in GitHub Desktop.
Get-iRule - for debugging
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function Get-iRule { | |
<# | |
.SYNOPSIS | |
Retrieve specified iRule(s) | |
.NOTES | |
iRule names are case-specific. | |
#> | |
[cmdletBinding()] | |
param( | |
$F5Session=$Script:F5Session, | |
[Alias("iRuleName")] | |
[Parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)] | |
[string[]]$Name='', | |
[Alias('iApp')] | |
[Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)] | |
[string]$Application='', | |
[Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)] | |
[string]$Partition | |
) | |
begin { | |
#Test that the F5 session is in a valid format | |
Test-F5Session($F5Session) | |
Write-Verbose "NB: iRule names are case-specific." | |
} | |
process { | |
foreach ($itemname in $Name) { | |
$URI = $F5Session.BaseURL + 'rule/{0}' -f (Get-ItemPath -Name $itemname -Application $Application -Partition $Partition) | |
$JSON = Invoke-F5RestMethod -Method Get -Uri $URI -F5Session $F5Session | |
if ($JSON.items -or $JSON.name) { | |
$items = Invoke-NullCoalescing {$JSON.items} {$JSON} | |
Write-Debug "JSON returned:" | |
Write-Debug $JSON | |
if(![string]::IsNullOrWhiteSpace($Application) -and ![string]::IsNullOrWhiteSpace($Partition)) { | |
$items = $items | Where-Object {$_.fullPath -eq "/$($_.partition)/$Application.app/$($_.name)"} | |
} | |
# $items | Add-ObjectDetail -TypeName 'PoshLTM.iRule' | Add-Member -MemberType AliasProperty -Name Definition -Value apiAnonymous; | |
$items | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment