# Get-EC2SecurityGroup with description

**URL:** <https://forums.powershell.org/t/get-ec2securitygroup-with-description/17799>\
**Category:** PowerShell Help\
**Created:** [October 20, 2021, 4:51pm UTC](https://forums.powershell.org/t/get-ec2securitygroup-with-description/17799 "2021-10-20T16:51:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kevin.corder](https://avatars.discourse-cdn.com/v4/letter/k/b9bd4f/32.png) [@Kevin.corder](https://forums.powershell.org/u/Kevin.corder)\
**Post date:** [October 20, 2021, 4:51pm UTC](https://forums.powershell.org/t/get-ec2securitygroup-with-description/17799/1 "2021-10-20T16:51:52Z")

</div>

```
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.

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [October 20, 2021, 5:19pm UTC](https://forums.powershell.org/t/get-ec2securitygroup-with-description/17799/2 "2021-10-20T17:19:18Z")

</div>

Kevin,  
Welcome to the forum. 👋🏽

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.

```auto
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:

> **[Everything you wanted to know about PSCustomObject - PowerShell](https://docs.microsoft.com/en-us/powershell/scripting/learn/deep-dives/everything-about-pscustomobject?view=powershell-7.2&viewFallbackFrom=powershell-7.1)**
>
> PSCustomObject is a simple way to create structured data.

> **[Powershell: Everything you wanted to know about PSCustomObject](https://powershellexplained.com/2016-10-28-powershell-everything-you-wanted-to-know-about-pscustomobject/)**
>
> PSCustomObjects are a great tool to add into your Powershell toolbelt. Let’s start with the basics and work our way into the more advanced features. The idea behind using a PSCustomObject is to have a very simple way to create structured data. Take a...

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:20pm UTC](https://forums.powershell.org/t/get-ec2securitygroup-with-description/17799/3 "2024-05-16T20:20:37Z")

</div>

Closed on May 16, 2024, 8:20pm UTC


