Skip to content

Commit 0029d93

Browse files
authored
Fix Visibility parameter validation in Set-EntraGroup (#1488)
1 parent 96e06a6 commit 0029d93

File tree

6 files changed

+87
-76
lines changed

6 files changed

+87
-76
lines changed

module/Entra/Microsoft.Entra/Groups/Set-EntraGroup.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ function Set-EntraGroup {
3333
[ValidateSet('true', 'false', IgnoreCase = $true)]
3434
[System.Nullable`1[System.Boolean]] $IsAssignableToRole,
3535

36-
[Parameter(ParameterSetName = 'UpdateGroupByGroupId', HelpMessage = 'Indicates whether this group can be assigned to a Microsoft Entra role.')]
37-
[ValidateSet('true', 'false', IgnoreCase = $true)]
36+
[Parameter(ParameterSetName = 'UpdateGroupByGroupId', HelpMessage = 'Specifies whether the group is private, public, or has hidden membership.')]
37+
[ValidateSet('Private', 'Public', 'HiddenMembership', IgnoreCase = $true)]
3838
[System.String] $Visibility,
3939

4040
[Parameter(ParameterSetName = 'UpdateGroupByGroupId', HelpMessage = 'Display name of the group.')]

module/EntraBeta/Microsoft.Entra.Beta/Groups/Set-EntraBetaGroup.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ function Set-EntraBetaGroup {
88
[Parameter(ParameterSetName = 'UpdateGroupByGroupId', HelpMessage = 'Specifies the group type and its membership.')]
99
[System.Collections.Generic.List`1[System.String]] $GroupTypes,
1010

11-
[Parameter(ParameterSetName = 'UpdateGroupByGroupId', HelpMessage = 'Indicates whether this group can be assigned to a Microsoft Entra role.')]
12-
[ValidateSet('true', 'false', IgnoreCase = $true)]
11+
[Parameter(ParameterSetName = 'UpdateGroupByGroupId', HelpMessage = 'Specifies whether the group is private, public, or has hidden membership.')]
12+
[ValidateSet('Private', 'Public', 'HiddenMembership', IgnoreCase = $true)]
1313
[System.String] $Visibility,
1414

1515
[Parameter(ParameterSetName = 'UpdateGroupByGroupId', HelpMessage = 'Description of the group.')]

module/docs/entra-powershell-beta/DirectoryManagement/Set-EntraBetaDirSyncEnabled.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Deactivating DirSync may take up to 72 hours, depending on the number of objects
4242

4343
If you re-enable DirSync, a full synchronization will occur, which may take significant time based on the number of objects in Microsoft Entra ID.
4444

45-
Additionally, if `BlockCloudObjectTakeoverThroughHardMatch` is enabled, re-enabling DirSync will block On-Prem to cloud object takeover/updates for all Microsoft Entra IDmastered objects. To allow syncing of these objects, set `BlockCloudObjectTakeoverThroughHardMatch` to false.
45+
Additionally, if `BlockCloudObjectTakeoverThroughHardMatch` is enabled, re-enabling DirSync will block On-Prem to cloud object takeover/updates for all Microsoft Entra ID-mastered objects. To allow syncing of these objects, set `BlockCloudObjectTakeoverThroughHardMatch` to false.
4646

4747
## Examples
4848

module/docs/entra-powershell-v1.0/DirectoryManagement/Set-EntraDirSyncEnabled.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ Turns directory synchronization on or off for a company.
2727

2828
```powershell
2929
Set-EntraDirSyncEnabled
30-
-EnableDirSync <Boolean>
31-
[-Force]
32-
[-TenantId <String>]
30+
-EnableDirSync <Boolean>
31+
[-Force]
32+
[-TenantId <String>]
3333
[<CommonParameters>]
3434
```
3535

@@ -43,7 +43,7 @@ Deactivating DirSync may take up to 72 hours, depending on the number of objects
4343

4444
If you re-enable DirSync, a full synchronization will occur, which may take significant time based on the number of objects in Microsoft Entra ID.
4545

46-
Additionally, if `BlockCloudObjectTakeoverThroughHardMatch` is enabled, re-enabling DirSync will block On-Prem to cloud object takeover/updates for all Microsoft Entra IDmastered objects. To allow syncing of these objects, set `BlockCloudObjectTakeoverThroughHardMatch` to false.
46+
Additionally, if `BlockCloudObjectTakeoverThroughHardMatch` is enabled, re-enabling DirSync will block On-Prem to cloud object takeover/updates for all Microsoft Entra ID-mastered objects. To allow syncing of these objects, set `BlockCloudObjectTakeoverThroughHardMatch` to false.
4747

4848
## Examples
4949

test/Entra/Groups/Set-EntraGroup.Tests.ps1

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,48 @@
22
# Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
33
# ------------------------------------------------------------------------------
44

5-
BeforeAll {
5+
BeforeAll {
66
if ((Get-Module -Name Microsoft.Entra.Groups) -eq $null) {
7-
Import-Module Microsoft.Entra.Groups
7+
Import-Module Microsoft.Entra.Groups
88
}
9-
Import-Module (Join-Path $PSScriptRoot "..\..\Common-Functions.ps1") -Force
9+
Import-Module (Join-Path $PSScriptRoot '..\..\Common-Functions.ps1') -Force
1010

1111
Mock -CommandName Update-MgGroup -MockWith {} -ModuleName Microsoft.Entra.Groups
12-
Mock -CommandName Get-EntraContext -MockWith { @{Scopes = @("Group.ReadWrite.All") } } -ModuleName Microsoft.Entra.Groups
12+
Mock -CommandName Get-EntraContext -MockWith { @{Scopes = @('Group.ReadWrite.All') } } -ModuleName Microsoft.Entra.Groups
1313
}
14-
15-
Describe "Set-EntraGroup" {
16-
Context "Test for Set-EntraGroup" {
17-
It "Should return empty object" {
18-
$result = Set-EntraGroup -GroupId aaaaaaaa-1111-2222-3333-cccccccccccc -DisplayName "demo" -MailEnabled $false -SecurityEnabled $true -MailNickName "demoNickname" -Description "test"
14+
15+
Describe 'Set-EntraGroup' {
16+
Context 'Test for Set-EntraGroup' {
17+
It 'Should return empty object' {
18+
$result = Set-EntraGroup -GroupId aaaaaaaa-1111-2222-3333-cccccccccccc -DisplayName 'demo' -MailEnabled $false -SecurityEnabled $true -MailNickname 'demoNickname' -Description 'test'
1919
$result | Should -BeNullOrEmpty
2020

2121
Should -Invoke -CommandName Update-MgGroup -ModuleName Microsoft.Entra.Groups -Times 1
2222
}
23-
It "Should execute successfully with Alias" {
24-
$result = Set-EntraGroup -Id aaaaaaaa-1111-2222-3333-cccccccccccc -DisplayName "demo" -MailEnabled $false -SecurityEnabled $true -MailNickName "demoNickname" -Description "test"
23+
It 'Should execute successfully with Alias' {
24+
$result = Set-EntraGroup -Id aaaaaaaa-1111-2222-3333-cccccccccccc -DisplayName 'demo' -MailEnabled $false -SecurityEnabled $true -MailNickname 'demoNickname' -Description 'test'
2525
$result | Should -BeNullOrEmpty
2626

2727
Should -Invoke -CommandName Update-MgGroup -ModuleName Microsoft.Entra.Groups -Times 1
2828
}
2929

30-
It "Should fail when GroupId is empty" {
30+
It 'Should fail when GroupId is empty' {
3131
{ Set-EntraGroup -GroupId } | Should -Throw "Missing an argument for parameter 'GroupId'*"
3232
}
33-
It "Should contain GroupId in parameters when passed GroupId to it" {
33+
It 'Should contain GroupId in parameters when passed GroupId to it' {
3434
Mock -CommandName Update-MgGroup -MockWith { $args } -ModuleName Microsoft.Entra.Groups
3535

3636
$result = Set-EntraGroup -GroupId aaaaaaaa-1111-2222-3333-cccccccccccc
3737
$params = Get-Parameters -data $result
38-
$params.GroupId | Should -Be "aaaaaaaa-1111-2222-3333-cccccccccccc"
39-
}
38+
$params.GroupId | Should -Be 'aaaaaaaa-1111-2222-3333-cccccccccccc'
39+
}
40+
It 'Should contain Visibility in parameters when passed Visibility to it' {
41+
Mock -CommandName Update-MgGroup -MockWith { $args } -ModuleName Microsoft.Entra.Groups
42+
43+
$result = Set-EntraGroup -GroupId aaaaaaaa-1111-2222-3333-cccccccccccc -Visibility 'Private'
44+
$params = Get-Parameters -data $result
45+
$params.Visibility | Should -Be 'Private'
46+
}
4047
It "Should contain 'User-Agent' header" {
4148
$userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Set-EntraGroup"
4249

@@ -48,20 +55,18 @@ Describe "Set-EntraGroup" {
4855
$true
4956
}
5057
}
51-
It "Should execute successfully without throwing an error " {
52-
# Disable confirmation prompts
58+
It 'Should execute successfully without throwing an error ' {
59+
# Disable confirmation prompts
5360
$originalDebugPreference = $DebugPreference
5461
$DebugPreference = 'Continue'
55-
62+
5663
try {
5764
# Act & Assert: Ensure the function doesn't throw an exception
5865
{ Set-EntraGroup -Id aaaaaaaa-1111-2222-3333-cccccccccccc } | Should -Not -Throw
66+
} finally {
67+
# Restore original confirmation preference
68+
$DebugPreference = $originalDebugPreference
5969
}
60-
finally {
61-
# Restore original confirmation preference
62-
$DebugPreference = $originalDebugPreference
63-
}
64-
}
70+
}
6571
}
6672
}
67-

test/EntraBeta/Groups/Set-EntraBetaGroup.Tests.ps1

Lines changed: 49 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,89 +2,95 @@
22
# Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
33
# ------------------------------------------------------------------------------
44

5-
BeforeAll {
5+
BeforeAll {
66
if ((Get-Module -Name Microsoft.Entra.Beta.Groups) -eq $null) {
7-
Import-Module Microsoft.Entra.Beta.Groups
7+
Import-Module Microsoft.Entra.Beta.Groups
88
}
9-
Import-Module (Join-Path $PSScriptRoot "..\..\Common-Functions.ps1") -Force
9+
Import-Module (Join-Path $PSScriptRoot '..\..\Common-Functions.ps1') -Force
1010

1111
Mock -CommandName Update-MgBetaGroup -MockWith {} -ModuleName Microsoft.Entra.Beta.Groups
12-
Mock -CommandName Get-EntraContext -MockWith { @{Scopes = @("Group.ReadWrite.All") } } -ModuleName Microsoft.Entra.Beta.Groups
12+
Mock -CommandName Get-EntraContext -MockWith { @{Scopes = @('Group.ReadWrite.All') } } -ModuleName Microsoft.Entra.Beta.Groups
1313
}
1414

15-
Describe "Set-EntraBetaGroup" {
16-
Context "Test for Set-EntraBetaGroup" {
17-
It "Should return empty object" {
18-
$result = Set-EntraBetaGroup -GroupId "aaaaaaaa-1111-2222-3333-cccccccccccc" -Description "Update Group" -DisplayName "Update My Test san" -MailEnabled $false -MailNickname "Update nickname" -SecurityEnabled $true
15+
Describe 'Set-EntraBetaGroup' {
16+
Context 'Test for Set-EntraBetaGroup' {
17+
It 'Should return empty object' {
18+
$result = Set-EntraBetaGroup -GroupId 'aaaaaaaa-1111-2222-3333-cccccccccccc' -Description 'Update Group' -DisplayName 'Update My Test san' -MailEnabled $false -MailNickname 'Update nickname' -SecurityEnabled $true
1919
$result | Should -BeNullOrEmpty
2020

2121
Should -Invoke -CommandName Update-MgBetaGroup -ModuleName Microsoft.Entra.Beta.Groups -Times 1
2222
}
2323

24-
It "Should execute successfully with Alias" {
25-
$result = Set-EntraBetaGroup -Id "aaaaaaaa-1111-2222-3333-cccccccccccc" -Description "Update Group" -DisplayName "Update My Test san" -MailEnabled $false -MailNickname "Update nickname" -SecurityEnabled $true
24+
It 'Should execute successfully with Alias' {
25+
$result = Set-EntraBetaGroup -Id 'aaaaaaaa-1111-2222-3333-cccccccccccc' -Description 'Update Group' -DisplayName 'Update My Test san' -MailEnabled $false -MailNickname 'Update nickname' -SecurityEnabled $true
2626
$result | Should -BeNullOrEmpty
2727

2828
Should -Invoke -CommandName Update-MgBetaGroup -ModuleName Microsoft.Entra.Beta.Groups -Times 1
2929
}
3030

31-
It "Should fail when GroupId is empty" {
31+
It 'Should fail when GroupId is empty' {
3232
{ Set-EntraBetaGroup -GroupId } | Should -Throw "Missing an argument for parameter 'GroupId'*"
33-
}
33+
}
3434

35-
It "Should fail when Description is empty" {
36-
{ Set-EntraBetaGroup -GroupId "aaaaaaaa-1111-2222-3333-cccccccccccc" -Description } | Should -Throw "Missing an argument for parameter 'Description'.*"
37-
}
35+
It 'Should fail when Description is empty' {
36+
{ Set-EntraBetaGroup -GroupId 'aaaaaaaa-1111-2222-3333-cccccccccccc' -Description } | Should -Throw "Missing an argument for parameter 'Description'.*"
37+
}
3838

39-
It "Should fail when DisplayName is empty" {
40-
{ Set-EntraBetaGroup -GroupId "aaaaaaaa-1111-2222-3333-cccccccccccc" -DisplayName } | Should -Throw "Missing an argument for parameter 'DisplayName'.*"
41-
}
39+
It 'Should fail when DisplayName is empty' {
40+
{ Set-EntraBetaGroup -GroupId 'aaaaaaaa-1111-2222-3333-cccccccccccc' -DisplayName } | Should -Throw "Missing an argument for parameter 'DisplayName'.*"
41+
}
4242

43-
It "Should fail when MailEnabled is empty" {
44-
{ Set-EntraBetaGroup -GroupId "aaaaaaaa-1111-2222-3333-cccccccccccc" -MailEnabled } | Should -Throw "Missing an argument for parameter*"
45-
}
43+
It 'Should fail when MailEnabled is empty' {
44+
{ Set-EntraBetaGroup -GroupId 'aaaaaaaa-1111-2222-3333-cccccccccccc' -MailEnabled } | Should -Throw 'Missing an argument for parameter*'
45+
}
4646

47-
It "Should fail when MailNickname is empty" {
48-
{ Set-EntraBetaGroup -GroupId "aaaaaaaa-1111-2222-3333-cccccccccccc" -MailNickname } | Should -Throw "Missing an argument for parameter*"
49-
}
47+
It 'Should fail when MailNickname is empty' {
48+
{ Set-EntraBetaGroup -GroupId 'aaaaaaaa-1111-2222-3333-cccccccccccc' -MailNickname } | Should -Throw 'Missing an argument for parameter*'
49+
}
5050

51-
It "Should fail when SecurityEnabled is empty" {
52-
{ Set-EntraBetaGroup -GroupId "aaaaaaaa-1111-2222-3333-cccccccccccc" -SecurityEnabled } | Should -Throw "Missing an argument for parameter*"
53-
}
51+
It 'Should fail when SecurityEnabled is empty' {
52+
{ Set-EntraBetaGroup -GroupId 'aaaaaaaa-1111-2222-3333-cccccccccccc' -SecurityEnabled } | Should -Throw 'Missing an argument for parameter*'
53+
}
5454

55-
It "Should contain GroupId in parameters when passed GroupId to it" {
55+
It 'Should contain GroupId in parameters when passed GroupId to it' {
5656
Mock -CommandName Update-MgBetaGroup -MockWith { $args } -ModuleName Microsoft.Entra.Beta.Groups
5757

58-
$result = Set-EntraBetaGroup -GroupId "aaaaaaaa-1111-2222-3333-cccccccccccc"
58+
$result = Set-EntraBetaGroup -GroupId 'aaaaaaaa-1111-2222-3333-cccccccccccc'
5959
$params = Get-Parameters -data $result
60-
$params.GroupId | Should -Be "aaaaaaaa-1111-2222-3333-cccccccccccc"
61-
}
60+
$params.GroupId | Should -Be 'aaaaaaaa-1111-2222-3333-cccccccccccc'
61+
}
62+
63+
It 'Should contain Visibility in parameters when passed Visibility to it' {
64+
Mock -CommandName Update-MgBetaGroup -MockWith { $args } -ModuleName Microsoft.Entra.Beta.Groups
65+
66+
$result = Set-EntraBetaGroup -GroupId 'aaaaaaaa-1111-2222-3333-cccccccccccc' -Visibility 'Private'
67+
$params = Get-Parameters -data $result
68+
$params.Visibility | Should -Be 'Private'
69+
}
6270

6371
It "Should contain 'User-Agent' header" {
6472
$userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Set-EntraBetaGroup"
65-
$result = Set-EntraBetaGroup -GroupId "aaaaaaaa-1111-2222-3333-cccccccccccc"
73+
$result = Set-EntraBetaGroup -GroupId 'aaaaaaaa-1111-2222-3333-cccccccccccc'
6674
$result | Should -BeNullOrEmpty
6775
$userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Set-EntraBetaGroup"
6876
Should -Invoke -CommandName Update-MgBetaGroup -ModuleName Microsoft.Entra.Beta.Groups -Times 1 -ParameterFilter {
6977
$Headers.'User-Agent' | Should -Be $userAgentHeaderValue
7078
$true
7179
}
72-
}
80+
}
7381

74-
It "Should execute successfully without throwing an error " {
75-
# Disable confirmation prompts
82+
It 'Should execute successfully without throwing an error ' {
83+
# Disable confirmation prompts
7684
$originalDebugPreference = $DebugPreference
7785
$DebugPreference = 'Continue'
78-
86+
7987
try {
8088
# Act & Assert: Ensure the function doesn't throw an exception
81-
{ Set-EntraBetaGroup -GroupId "aaaaaaaa-1111-2222-3333-cccccccccccc" -Debug } | Should -Not -Throw
82-
}
83-
finally {
84-
# Restore original confirmation preference
85-
$DebugPreference = $originalDebugPreference
89+
{ Set-EntraBetaGroup -GroupId 'aaaaaaaa-1111-2222-3333-cccccccccccc' -Debug } | Should -Not -Throw
90+
} finally {
91+
# Restore original confirmation preference
92+
$DebugPreference = $originalDebugPreference
8693
}
87-
}
94+
}
8895
}
8996
}
90-

0 commit comments

Comments
 (0)