From c014efc84aea6d5eced24edf3d1b0fe43d41a46b Mon Sep 17 00:00:00 2001 From: Kennedy Kangethe Munga Date: Fri, 15 Aug 2025 10:33:01 +0300 Subject: [PATCH 1/2] AppendSelected parameter --- .../Entra/Microsoft.Entra/Groups/Get-EntraGroup.ps1 | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/module/Entra/Microsoft.Entra/Groups/Get-EntraGroup.ps1 b/module/Entra/Microsoft.Entra/Groups/Get-EntraGroup.ps1 index 922b7790c3..2185bc2697 100644 --- a/module/Entra/Microsoft.Entra/Groups/Get-EntraGroup.ps1 +++ b/module/Entra/Microsoft.Entra/Groups/Get-EntraGroup.ps1 @@ -25,7 +25,9 @@ function Get-EntraGroup { [Parameter(Mandatory = $false, ValueFromPipeline = $false, ValueFromPipelineByPropertyName = $true, HelpMessage = "Properties to include in the results.")] [Alias("Select")] - [System.String[]] $Property + [System.String[]] $Property, + + [switch] $AppendSelected ) begin { @@ -41,6 +43,7 @@ function Get-EntraGroup { $params = @{} $customHeaders = New-EntraCustomHeaders -Command $MyInvocation.MyCommand $keysChanged = @{SearchString = "Filter"; ObjectId = "Id" } + $defaultProperties = "id,displayName,createdDateTime,createdDateTime,groupTypes,mailEnabled,mailNickname,securityEnabled,visibility,description" if ($null -ne $PSBoundParameters["OutVariable"]) { $params["OutVariable"] = $PSBoundParameters["OutVariable"] } @@ -101,8 +104,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 ============================") From af3ba2dbc85662208a9d91af7ea77cd5aff3f9a5 Mon Sep 17 00:00:00 2001 From: Kennedy Kangethe Munga Date: Tue, 19 Aug 2025 12:00:47 +0300 Subject: [PATCH 2/2] Get-EntraGroup --- .../Microsoft.Entra/Groups/Get-EntraGroup.ps1 | 12 +++- .../Groups/Get-EntraGroup.md | 55 +++++++++++++++++-- test/Entra/Groups/Get-EntraGroup.Tests.ps1 | 39 +++++++++++++ 3 files changed, 99 insertions(+), 7 deletions(-) diff --git a/module/Entra/Microsoft.Entra/Groups/Get-EntraGroup.ps1 b/module/Entra/Microsoft.Entra/Groups/Get-EntraGroup.ps1 index 2185bc2697..5e04370d96 100644 --- a/module/Entra/Microsoft.Entra/Groups/Get-EntraGroup.ps1 +++ b/module/Entra/Microsoft.Entra/Groups/Get-EntraGroup.ps1 @@ -6,27 +6,35 @@ 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, + [Parameter(ParameterSetName = "Append", Mandatory = $true, HelpMessage = "Specifies whether to append the selected properties.")] [switch] $AppendSelected ) @@ -43,7 +51,7 @@ function Get-EntraGroup { $params = @{} $customHeaders = New-EntraCustomHeaders -Command $MyInvocation.MyCommand $keysChanged = @{SearchString = "Filter"; ObjectId = "Id" } - $defaultProperties = "id,displayName,createdDateTime,createdDateTime,groupTypes,mailEnabled,mailNickname,securityEnabled,visibility,description" + $defaultProperties = "id,displayName,createdDateTime,deletedDateTime,groupTypes,mailEnabled,mailNickname,securityEnabled,visibility,description" if ($null -ne $PSBoundParameters["OutVariable"]) { $params["OutVariable"] = $PSBoundParameters["OutVariable"] } diff --git a/module/docs/entra-powershell-v1.0/Groups/Get-EntraGroup.md b/module/docs/entra-powershell-v1.0/Groups/Get-EntraGroup.md index 87a37782cf..43636fb828 100644 --- a/module/docs/entra-powershell-v1.0/Groups/Get-EntraGroup.md +++ b/module/docs/entra-powershell-v1.0/Groups/Get-EntraGroup.md @@ -33,7 +33,7 @@ Get-EntraGroup [] ``` -### GetByValue +### GetVague ```powershell Get-EntraGroup @@ -53,6 +53,20 @@ Get-EntraGroup [] ``` +### Append + +```powershell +Get-EntraGroup + -Property ] + [-Top ] + [-All] + [-Filter ] + [-SearchString ] + [] +``` + ## DESCRIPTION The `Get-EntraGroup` cmdlet gets a group in Microsoft Entra ID. Specify the `ObjectId` parameter to get a specific group. @@ -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 @@ -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 @@ -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 @@ -263,7 +292,7 @@ Specifies a search string. ```yaml Type: System.String -Parameter Sets: GetValue +Parameter Sets: GetValue, Append Aliases: Required: False @@ -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 @@ -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). diff --git a/test/Entra/Groups/Get-EntraGroup.Tests.ps1 b/test/Entra/Groups/Get-EntraGroup.Tests.ps1 index b02dc98358..658e545419 100644 --- a/test/Entra/Groups/Get-EntraGroup.Tests.ps1 +++ b/test/Entra/Groups/Get-EntraGroup.Tests.ps1 @@ -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"