Get-EC2SecurityGroup with description

function Get-EC2SecurityGroupDetails {
    param (
    [parameter()]
    [string] $GroupName)
    (Get-EC2SecurityGroup | Where-Object GroupName -EQ $GroupName)
    .IpPermissions |
                      ForEach-Object {
        [PSCustomObject]@{
            IpProtocol = $_.IpProtocol
            FromPort   = $_.FromPort
            ToPort     = $_.ToPort
            Ipv4Ranges = $_.Ipv4Ranges.CidrIp
        }
    }
}

How can I modify this function to include Group Name and Description? currently it lists only the specified Security Group, I’d like to list all Security Groups within the current region with their details. Any help would be greatly appreciated.

Kevin,
Welcome to the forum. :wave:t4:

I don’t have experiences with EC2 but something like this may work. If not it might show you the genereal idea how a PSCustomObject works.

function Get-EC2SecurityGroupDetails {
    param (
        [string] $GroupName
    )
    (Get-EC2SecurityGroup | Where-Object GroupName -EQ $GroupName).IpPermissions |
    ForEach-Object {
        [PSCustomObject]@{
            IpProtocol  = $_.IpProtocol
            FromPort    = $_.FromPort
            ToPort      = $_.ToPort
            Ipv4Ranges  = $_.Ipv4Ranges.CidrIp
            GroupName   = $GroupName
            Description = $_.Description
        }
    }
}

Here you can read more about that topic: