public/Get-SecurityGroupRule.ps1

function Get-ZStackSecurityGroupRule {
    # .SYNOPSIS
    # Returns rules for the selected security groups or connection.
    # .DESCRIPTION
    # ZStack PowerCLI (ZStack.PowerCLI 1.1.5) uses CLI 1.1.5, commit 6fcf509ff540d0098f54c1c33609dbe9f572c837.
    # Connection configuration namespace: zstack-powershell.
    # .LINK
    # https://github.com/terraform-zstack-modules/zstack-cli-go/blob/main/docs/powershell.md
    [CmdletBinding(DefaultParameterSetName = 'Inventory')]
    param(
        [Parameter(Mandatory, ParameterSetName = 'ByParent', ValueFromPipeline)] [ValidateNotNullOrEmpty()] [object[]] $SecurityGroup,
        [ValidateNotNullOrEmpty()] [ValidatePattern('\A[A-Za-z0-9-]{1,128}\z')] [string[]] $Id,
        [object] $Server
    )

    begin { $targets = [System.Collections.Generic.List[object]]::new() }
    process { if ($PSCmdlet.ParameterSetName -ceq 'ByParent') { $targets.AddRange($SecurityGroup) } }
    end {
        if ($PSCmdlet.ParameterSetName -ceq 'ByParent') {
            Get-CloudInventory -Type SecurityGroupRule -Server $Server -Id $Id -ParentField securityGroupUuid -ParentType SecurityGroup -Parent ($targets.ToArray())
        } else {
            Get-CloudInventory -Type SecurityGroupRule -Server $Server -Id $Id
        }
    }
}