functions/groups/Get-Group.ps1

function Get-Group {
    <#
    .SYNOPSIS
    Get Group by ID
 
    .DESCRIPTION
    Get Group by ID
 
    .EXAMPLE
    $session = New-TssSession -SecretServer https://alpha -Credential $ssCred
    Get-TssGroup -TssSession $session -Id 8
 
    Get details on Group ID 8
 
    .LINK
    https://thycotic-ps.github.io/thycotic.secretserver/commands/Get-TssGroup
 
    .LINK
    https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/<folder>/Get-Group.ps1
 
    .NOTES
    Requires TssSession object returned by New-TssSession
    #>

    [CmdletBinding()]
    [OutputType('TssGroup')]
    param (
        # TssSession object created by New-TssSession for auth
        [Parameter(Mandatory, ValueFromPipeline, Position = 0)]
        [TssSession]
        $TssSession,

        # Short description for parameter
        [Parameter(Mandatory, ValueFromPipelineByPropertyName)]
        [Alias('GroupId')]
        [int[]]
        $Id
    )
    begin {
        $tssParams = $PSBoundParameters
        $invokeParams = . $GetInvokeTssParams $TssSession
    }
    process {
        Write-Verbose "Provided command parameters: $(. $GetInvocation $PSCmdlet.MyInvocation)"
        if ($tssParams.ContainsKey('TssSession') -and $TssSession.IsValidSession()) {
            . $CheckVersion $TssSession '10.9.000000' $PSCmdlet.MyInvocation
            foreach ($group in $Id) {
                $restResponse = $null
                $uri = $TssSession.ApiUrl, 'groups', $group -join '/'
                $invokeParams.Uri = $uri
                $invokeParams.Method = 'GET'

                Write-Verbose "Performing the operation $($invokeParams.Method) $uri with $body"
                try {
                    $restResponse = . $InvokeApi @invokeParams
                } catch {
                    Write-Warning "Issue getting group [$group]"
                    $err = $_
                    . $ErrorHandling $err
                }

                if ($restResponse) {
                    foreach ($g in $restResponse) {
                        if ($g.HasGroupOwners) {
                            $oGroups = @()
                            foreach ($prop in $g.ownerGroups.PSObject.Properties.Name) {
                                $oGroups += [pscustomobject]@{
                                    GroupId   = $prop
                                    GroupName = $g.ownerGroups.$prop
                                }
                            }
                            $oUsers = @()
                            foreach ($prop in $g.ownerUsers.PSObject.Properties.Name) {
                                $oUsers += [pscustomobject]@{
                                    UserId   = $prop
                                    Username = $g.ownerUsers.$prop
                                }
                            }
                        }

                        [TssGroup]@{
                            AdGuid         = $g.AdGuid
                            CanEditMembers = $g.canEditMembers
                            Created        = $g.Created
                            DomainId       = $g.DomainId
                            DomainName     = $g.DomainName
                            Enabled        = $g.Enabled
                            HasGroupOwners = $g.HasGroupOwners
                            Id             = $g.Id
                            IsEditable     = $g.IsEditable
                            Name           = $g.Name
                            OwnerGroups    = $oGroups
                            Owners         = $g.Owners
                            OwnerUsers     = $oUsers
                            Synchronized   = $g.Synchronized
                            SynchronizeNow = $g.SynchronizeNow
                            SystemGroup    = $g.SystemGroup
                        }
                    }
                }
            }
        } else {
            Write-Warning 'No valid session found'
        }
    }
}