diff --git a/PowerFGT/Public/cmdb/user/group.ps1 b/PowerFGT/Public/cmdb/user/group.ps1 index 27d36970..e16d9f3b 100644 --- a/PowerFGT/Public/cmdb/user/group.ps1 +++ b/PowerFGT/Public/cmdb/user/group.ps1 @@ -33,7 +33,7 @@ function Add-FGTUserGroup { Param( [Parameter (Mandatory = $true)] [string]$name, - [Parameter (Mandatory = $true)] + [Parameter (Mandatory = $false)] [string[]]$member, [Parameter (Mandatory = $false)] [hashtable]$data, @@ -63,14 +63,16 @@ function Add-FGTUserGroup { $usergroup | add-member -name "name" -membertype NoteProperty -Value $name - #Add member to members Array - $members = @( ) - foreach ( $m in $member ) { - $member_name = @{ } - $member_name.add( 'name', $m) - $members += $member_name + if ( $PsBoundParameters.ContainsKey('member') ) { + #Add member to members Array + $members = @( ) + foreach ( $m in $member ) { + $member_name = @{ } + $member_name.add( 'name', $m) + $members += $member_name + } + $usergroup | add-member -name "member" -membertype NoteProperty -Value $members } - $usergroup | add-member -name "member" -membertype NoteProperty -Value $members if ( $PsBoundParameters.ContainsKey('data') ) { $data.GetEnumerator() | ForEach-Object { diff --git a/Tests/integration/UserGroup.Tests.ps1 b/Tests/integration/UserGroup.Tests.ps1 index 6e836dd4..62bf5c02 100644 --- a/Tests/integration/UserGroup.Tests.ps1 +++ b/Tests/integration/UserGroup.Tests.ps1 @@ -98,6 +98,13 @@ Describe "Add User Group" { Get-FGTUserGroup -name $pester_usergroup1 | Remove-FGTUserGroup -confirm:$false } + It "Add User Group $pester_usergroup1 (with 0 member)" { + Add-FGTUserGroup -Name $pester_usergroup1 + $usergroup = Get-FGTUserGroup -name $pester_usergroup1 + $usergroup.name | Should -Be $pester_usergroup1 + ($usergroup.member).count | Should -Be "0" + } + It "Add User Group $pester_usergroup1 (with 1 member)" { Add-FGTUserGroup -Name $pester_usergroup1 -member $pester_userlocal $usergroup = Get-FGTUserGroup -name $pester_usergroup1