Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions module/Entra/Microsoft.Entra/Groups/Get-EntraGroup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,36 @@ function Get-EntraGroup {
[CmdletBinding(DefaultParameterSetName = 'GetQuery')]
param (
[Parameter(ParameterSetName = "GetQuery", ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "The maximum number of items to return.")]
[Parameter(ParameterSetName = "Append", ValueFromPipeline = $false, ValueFromPipelineByPropertyName = $true, HelpMessage = "The maximum number of items to return.")]
[Alias("Limit")]
[System.Nullable`1[System.Int32]] $Top,

[Parameter(ParameterSetName = "GetQuery", ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Filter the results based on the specified criteria.")]
[Parameter(ParameterSetName = "Append", ValueFromPipeline = $false, ValueFromPipelineByPropertyName = $true, HelpMessage = "Filter the results based on the specified criteria.")]
[System.String] $Filter,

[Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Specifies whether to return all objects.")]
[switch] $All,

[Parameter(ParameterSetName = "GetVague", ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Search for a group by its name, email, or mail nickname.")]
[Parameter(ParameterSetName = "Append", ValueFromPipeline = $false, ValueFromPipelineByPropertyName = $true, HelpMessage = "Search for a group by its name, email, or mail nickname.")]
[System.String] $SearchString,

[Alias('ObjectId')]
[Parameter(ParameterSetName = "GetById", Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "The ID of the group to retrieve. Should be a valid GUID value.")]
[Parameter(ParameterSetName = "Append", Mandatory = $false, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "The ID of the group to retrieve. Should be a valid GUID value.")]
[ValidateNotNullOrEmpty()]
[Guid] $GroupId,

[Parameter(Mandatory = $false, ValueFromPipeline = $false, ValueFromPipelineByPropertyName = $true, HelpMessage = "Properties to include in the results.")]
[Parameter(ParameterSetName = "GetQuery", Mandatory = $false, ValueFromPipeline = $false, ValueFromPipelineByPropertyName = $true, HelpMessage = "Properties to include in the results.")]
[Parameter(ParameterSetName = "GetVague", Mandatory = $false, ValueFromPipeline = $false, ValueFromPipelineByPropertyName = $true, HelpMessage = "Properties to include in the results.")]
[Parameter(ParameterSetName = "GetById", Mandatory = $false, ValueFromPipeline = $false, ValueFromPipelineByPropertyName = $true, HelpMessage = "Properties to include in the results.")]
[Parameter(ParameterSetName = "Append", Mandatory = $true, ValueFromPipeline = $false, ValueFromPipelineByPropertyName = $true, HelpMessage = "Properties to include in the results.")]
[Alias("Select")]
[System.String[]] $Property
[System.String[]] $Property,

[Parameter(ParameterSetName = "Append", Mandatory = $true, HelpMessage = "Specifies whether to append the selected properties.")]
[switch] $AppendSelected
)

begin {
Expand All @@ -41,6 +51,7 @@ function Get-EntraGroup {
$params = @{}
$customHeaders = New-EntraCustomHeaders -Command $MyInvocation.MyCommand
$keysChanged = @{SearchString = "Filter"; ObjectId = "Id" }
$defaultProperties = "id,displayName,createdDateTime,deletedDateTime,groupTypes,mailEnabled,mailNickname,securityEnabled,visibility,description"
if ($null -ne $PSBoundParameters["OutVariable"]) {
$params["OutVariable"] = $PSBoundParameters["OutVariable"]
}
Expand Down Expand Up @@ -101,8 +112,11 @@ function Get-EntraGroup {
if ($null -ne $PSBoundParameters["ProgressAction"]) {
$params["ProgressAction"] = $PSBoundParameters["ProgressAction"]
}
if ($null -ne $PSBoundParameters["Property"]) {
$params["Property"] = $PSBoundParameters["Property"]
if ($null -ne $Property -and $Property.Count -gt 0) {
$params["Property"] = $Property
}
if ($PSBoundParameters.ContainsKey("AppendSelected")) {
$params["Property"] = $defaultProperties + "," + $params["Property"]
}

Write-Debug("============================ TRANSFORMATIONS ============================")
Expand Down
55 changes: 50 additions & 5 deletions module/docs/entra-powershell-v1.0/Groups/Get-EntraGroup.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Get-EntraGroup
[<CommonParameters>]
```

### GetByValue
### GetVague

```powershell
Get-EntraGroup
Expand All @@ -53,6 +53,20 @@ Get-EntraGroup
[<CommonParameters>]
```

### Append

```powershell
Get-EntraGroup
-Property <String[]
-AppendSelected
[-GroupId <String>]
[-Top <Int32>]
[-All]
[-Filter <String>]
[-SearchString <String>]
[<CommonParameters>]
```

## DESCRIPTION

The `Get-EntraGroup` cmdlet gets a group in Microsoft Entra ID. Specify the `ObjectId` parameter to get a specific group.
Expand Down Expand Up @@ -206,6 +220,21 @@ bbbbbbbb-5555-5555-0000-qqqqqqqqqqqq HelpDesk admin group True {

This example demonstrates how to return only a specific property of a group. You can use `-Select` alias or `-Property`.

### Example 9: Get groups with specific properties and append the selected properties

```powershell
Connect-Entra -Scopes 'GroupMember.Read.All'
Get-EntraGroup -GroupId 'aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb' -Property IsSubscribedByMail -AppendSelected | Select-Object Id, DisplayName, MailEnabled, Visibility, IsSubscribedByMail | Format-Table -AutoSize
```

```Output
Id DisplayName MailEnabled Visibility IsSubscribedByMail
-- ----------- --------------- ---------- ----------
aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb SimpleGroup False Public False
```

This example demonstrates how to append a selected property to the default properties.

## PARAMETERS

### -All
Expand All @@ -231,7 +260,7 @@ This parameter controls which objects are returned.

```yaml
Type: System.String
Parameter Sets: GetQuery
Parameter Sets: GetQuery, Append
Aliases:

Required: False
Expand All @@ -247,7 +276,7 @@ The unique identifier of a group in Microsoft Entra ID (GroupId)

```yaml
Type: System.String
Parameter Sets: GetById
Parameter Sets: GetById, Append
Aliases: ObjectId

Required: True
Expand All @@ -263,7 +292,7 @@ Specifies a search string.

```yaml
Type: System.String
Parameter Sets: GetValue
Parameter Sets: GetValue, Append
Aliases:

Required: False
Expand All @@ -279,7 +308,7 @@ Specifies the maximum number of records to return.

```yaml
Type: System.Int32
Parameter Sets: GetQuery
Parameter Sets: GetQuery, Append
Aliases: Limit

Required: False
Expand All @@ -305,6 +334,22 @@ Accept pipeline input: False
Accept wildcard characters: False
```

### -AppendSelected

List all pages.

```yaml
Type: System.Management.Automation.SwitchParameter
Parameter Sets: Append
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
```

### CommonParameters

This cmdlet supports the common parameters: `-Debug`, `-ErrorAction`, `-ErrorVariable`, `-InformationAction`, `-InformationVariable`, `-OutVariable`, `-OutBuffer`, `-PipelineVariable`, `-Verbose`, `-WarningAction`, and `-WarningVariable`. For more information, see [about_CommonParameters](https://go.microsoft.com/fwlink/?LinkID=113216).
Expand Down
39 changes: 39 additions & 0 deletions test/Entra/Groups/Get-EntraGroup.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,45 @@ Describe "Get-EntraGroup" {
$params = Get-Parameters -data $result.Parameters
$params.Filter | Should -Match "demo"
}
It "Should return specified properties" {
$scriptblock = {
return @(
[PSCustomObject]@{
"DisplayName" = "demo"
"Id" = "aaaaaaaa-1111-2222-3333-cccccccccccc"
"MailEnabled" = $false
}
)
}

Mock -CommandName Get-MgGroup -MockWith $scriptblock -ModuleName Microsoft.Entra.Groups
$result = Get-EntraGroup -GroupId "aaaaaaaa-1111-2222-3333-cccccccccccc" -Property Id,DisplayName,MailEnabled
$result.ObjectId | should -Be "aaaaaaaa-1111-2222-3333-cccccccccccc"
}
It "Should return append specified properties to the default properties" {
$scriptblock = {
return @(
[PSCustomObject]@{
"DisplayName" = "demo"
"Id" = "aaaaaaaa-1111-2222-3333-cccccccccccc"
"MailEnabled" = $false
"CreatedDateTime" = "2023-01-01T00:00:00Z"
"IsSubscribedByMail" = $false
"DeletedDateTime" = $null
"GroupTypes" = @("Unified")
"MailNickname" = "demoNickname"
"SecurityEnabled" = $true
"Visibility" = "Public"
"Description" = "test"
}
)
}

Mock -CommandName Get-MgGroup -MockWith $scriptblock -ModuleName Microsoft.Entra.Groups
$result = Get-EntraGroup -GroupId "aaaaaaaa-1111-2222-3333-cccccccccccc" -Property IsSubscribedByMail
$result.ObjectId | should -Be "aaaaaaaa-1111-2222-3333-cccccccccccc"
$result.IsSubscribedByMail | should -Be $false
}
It "Should contain 'User-Agent' header" {
$userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraGroup"
$result = Get-EntraGroup -GroupId "aaaaaaaa-1111-2222-3333-cccccccccccc"
Expand Down