diff --git a/Modules/VMware.vSphere.SsoAdmin/Group.ps1 b/Modules/VMware.vSphere.SsoAdmin/Group.ps1 index d534302..2348a52 100644 --- a/Modules/VMware.vSphere.SsoAdmin/Group.ps1 +++ b/Modules/VMware.vSphere.SsoAdmin/Group.ps1 @@ -23,7 +23,7 @@ function New-SsoGroup { Specifies the name of the group. .PARAMETER Description - Specifies optionaldescription of the group. + Specifies an optional description of the group. .PARAMETER Server Specifies the vSphere Sso Admin Server on which you want to run the cmdlet. @@ -32,7 +32,7 @@ function New-SsoGroup { .EXAMPLE New-SsoGroup -Name 'myGroup' -Description 'My Group Description' - Creates local groupwith user 'myGroup' and description 'My Group Description' + Creates a local group with name 'myGroup' and description 'My Group Description' #> @@ -89,65 +89,6 @@ function New-SsoGroup { } } -function Set-SsoGroup { -} - -function Remove-SsoGroup { - <# - .NOTES - =========================================================================== - Created on: 5/25/2021 - Created by: Dimitar Milov - Twitter: @dimitar_milov - Github: https://github.com/dmilov - =========================================================================== - .DESCRIPTION - This function removes existing local group. - - .PARAMETER Group - Specifies the Group instance to remove. - - .EXAMPLE - $ssoAdminConnection = Connect-SsoAdminServer -Server my.vc.server -User ssoAdmin@vsphere.local -Password 'ssoAdminStrongPa$$w0rd' - $myNewGroup = New-SsoGroup -Server $ssoAdminConnection -Name 'myGroup' - Remove-SsoGroup -Group $myNewGroup - - Remove plocal group with name 'myGroup' -#> - [CmdletBinding(ConfirmImpact = 'High')] - param( - [Parameter( - Mandatory = $true, - ValueFromPipeline = $true, - ValueFromPipelineByPropertyName = $false, - HelpMessage = 'Group instance you want to remove from specified servers')] - [VMware.vSphere.SsoAdminClient.DataTypes.Group] - $Group) - - Process { - try { - foreach ($g in $Group) { - $ssoAdminClient = $g.GetClient() - if ((-not $ssoAdminClient)) { - Write-Error "Object '$g' is from disconnected server" - continue - } - - $ssoAdminClient.RemoveLocalGroup($g) - } - } - catch { - Write-Error (FormatError $_.Exception) - } - } -} - -function Add-PrincipalToSsoGroup { -} - -function Remove-PrincipalFromSsoGroup { -} - function Get-SsoGroup { <# .NOTES @@ -247,3 +188,125 @@ function Get-SsoGroup { } } } + +function Set-SsoGroup { + <# + .NOTES + =========================================================================== + Created on: 5/25/2021 + Created by: Dimitar Milov + Twitter: @dimitar_milov + Github: https://github.com/dmilov + =========================================================================== + + .SYNOPSIS + Updates Local Sso Group + + .DESCRIPTION + Updates Local Sso Group details + + .PARAMETER Gtoup + Specifies the group instace to update. + + .PARAMETER Description + Specifies a description of the group. + + .EXAMPLE + $myGroup = New-SsoGroup -Name 'myGroup' + $myGroup | Set-SsoGroup -Description 'My Group Description' + + Updates local group $myGroup with description 'My Group Description' + + #> + + [CmdletBinding()] + param( + [Parameter( + Mandatory = $true, + ValueFromPipeline = $true, + ValueFromPipelineByPropertyName = $false, + HelpMessage = 'Group instance you want to update')] + [VMware.vSphere.SsoAdminClient.DataTypes.Group] + $Group, + + [Parameter( + Mandatory = $false, + ValueFromPipeline = $false, + ValueFromPipelineByPropertyName = $false, + HelpMessage = 'Specifies the description of the group')] + [string] + $Description) + + Process { + try { + foreach ($g in $Group) { + $ssoAdminClient = $g.GetClient() + if ((-not $ssoAdminClient)) { + Write-Error "Object '$g' is from disconnected server" + continue + } + + $ssoAdminClient.UpdateLocalGroup($g, $Description) + } + } + catch { + Write-Error (FormatError $_.Exception) + } + } +} + +function Remove-SsoGroup { + <# + .NOTES + =========================================================================== + Created on: 5/25/2021 + Created by: Dimitar Milov + Twitter: @dimitar_milov + Github: https://github.com/dmilov + =========================================================================== + .DESCRIPTION + This function removes existing local group. + + .PARAMETER Group + Specifies the Group instance to remove. + + .EXAMPLE + $ssoAdminConnection = Connect-SsoAdminServer -Server my.vc.server -User ssoAdmin@vsphere.local -Password 'ssoAdminStrongPa$$w0rd' + $myNewGroup = New-SsoGroup -Server $ssoAdminConnection -Name 'myGroup' + Remove-SsoGroup -Group $myNewGroup + + Remove plocal group with name 'myGroup' +#> + [CmdletBinding(ConfirmImpact = 'High')] + param( + [Parameter( + Mandatory = $true, + ValueFromPipeline = $true, + ValueFromPipelineByPropertyName = $false, + HelpMessage = 'Group instance you want to remove')] + [VMware.vSphere.SsoAdminClient.DataTypes.Group] + $Group) + + Process { + try { + foreach ($g in $Group) { + $ssoAdminClient = $g.GetClient() + if ((-not $ssoAdminClient)) { + Write-Error "Object '$g' is from disconnected server" + continue + } + + $ssoAdminClient.RemoveLocalGroup($g) + } + } + catch { + Write-Error (FormatError $_.Exception) + } + } +} + +function Add-PrincipalToSsoGroup { +} + +function Remove-PrincipalFromSsoGroup { +} diff --git a/Modules/VMware.vSphere.SsoAdmin/PersonUser.ps1 b/Modules/VMware.vSphere.SsoAdmin/PersonUser.ps1 index 8a17dd5..305e66f 100644 --- a/Modules/VMware.vSphere.SsoAdmin/PersonUser.ps1 +++ b/Modules/VMware.vSphere.SsoAdmin/PersonUser.ps1 @@ -498,7 +498,7 @@ function Remove-SsoPersonUser { Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $false, - HelpMessage = 'Person User instance you want to remove from specified servers')] + HelpMessage = 'Person User instance you want to remove')] [VMware.vSphere.SsoAdminClient.DataTypes.PersonUser] $User) diff --git a/Modules/VMware.vSphere.SsoAdmin/net45/VMware.vSphere.SsoAdmin.Utils.dll b/Modules/VMware.vSphere.SsoAdmin/net45/VMware.vSphere.SsoAdmin.Utils.dll index 99a6d0c..97e1748 100644 Binary files a/Modules/VMware.vSphere.SsoAdmin/net45/VMware.vSphere.SsoAdmin.Utils.dll and b/Modules/VMware.vSphere.SsoAdmin/net45/VMware.vSphere.SsoAdmin.Utils.dll differ diff --git a/Modules/VMware.vSphere.SsoAdmin/net45/VMware.vSphere.SsoAdminClient.dll b/Modules/VMware.vSphere.SsoAdmin/net45/VMware.vSphere.SsoAdminClient.dll index 47dd9ad..4c0a426 100644 Binary files a/Modules/VMware.vSphere.SsoAdmin/net45/VMware.vSphere.SsoAdminClient.dll and b/Modules/VMware.vSphere.SsoAdmin/net45/VMware.vSphere.SsoAdminClient.dll differ diff --git a/Modules/VMware.vSphere.SsoAdmin/netcoreapp3.1/VMware.vSphere.SsoAdmin.Utils.dll b/Modules/VMware.vSphere.SsoAdmin/netcoreapp3.1/VMware.vSphere.SsoAdmin.Utils.dll index a94c1da..4266670 100644 Binary files a/Modules/VMware.vSphere.SsoAdmin/netcoreapp3.1/VMware.vSphere.SsoAdmin.Utils.dll and b/Modules/VMware.vSphere.SsoAdmin/netcoreapp3.1/VMware.vSphere.SsoAdmin.Utils.dll differ diff --git a/Modules/VMware.vSphere.SsoAdmin/netcoreapp3.1/VMware.vSphere.SsoAdminClient.dll b/Modules/VMware.vSphere.SsoAdmin/netcoreapp3.1/VMware.vSphere.SsoAdminClient.dll index 9048ffc..9c2c9c6 100644 Binary files a/Modules/VMware.vSphere.SsoAdmin/netcoreapp3.1/VMware.vSphere.SsoAdminClient.dll and b/Modules/VMware.vSphere.SsoAdmin/netcoreapp3.1/VMware.vSphere.SsoAdminClient.dll differ diff --git a/Modules/VMware.vSphere.SsoAdmin/src/VMware.vSphere.SsoAdmin.Client/VMware.vSphere.SsoAdminClient/SsoAdminClient.cs b/Modules/VMware.vSphere.SsoAdmin/src/VMware.vSphere.SsoAdmin.Client/VMware.vSphere.SsoAdminClient/SsoAdminClient.cs index 34f8d1a..eb64fe2 100644 --- a/Modules/VMware.vSphere.SsoAdmin/src/VMware.vSphere.SsoAdmin.Client/VMware.vSphere.SsoAdminClient/SsoAdminClient.cs +++ b/Modules/VMware.vSphere.SsoAdmin/src/VMware.vSphere.SsoAdmin.Client/VMware.vSphere.SsoAdminClient/SsoAdminClient.cs @@ -379,6 +379,41 @@ namespace VMware.vSphere.SsoAdminClient } } + public DataTypes.Group UpdateLocalGroup(DataTypes.Group group, string description) + { + if (description == null) { + description = string.Empty; + } + + // Create Authorization Invocation Context + var authorizedInvocationContext = + CreateAuthorizedInvocationContext(); + + // Invoke SSO Admin DeleteLocalPrincipal operation + var updatedGroup = authorizedInvocationContext. + InvokeOperation(() => + _ssoAdminBindingClient.UpdateLocalGroupDetailsAsync( + new ManagedObjectReference + { + type = "SsoAdminPrincipalManagementService", + Value = "principalManagementService" + }, + group.Name, + new SsoAdminGroupDetails + { + description = description + })).Result; + + if (updatedGroup != null) + { + return FindGroup(updatedGroup.name, updatedGroup.domain, authorizedInvocationContext); + } + else + { + return null; + } + } + public void RemoveLocalGroup(DataTypes.Group group) { diff --git a/Modules/VMware.vSphere.SsoAdmin/src/test/Group.Tests.ps1 b/Modules/VMware.vSphere.SsoAdmin/src/test/Group.Tests.ps1 index 613c864..80ee7dc 100644 --- a/Modules/VMware.vSphere.SsoAdmin/src/test/Group.Tests.ps1 +++ b/Modules/VMware.vSphere.SsoAdmin/src/test/Group.Tests.ps1 @@ -127,4 +127,21 @@ Describe "SsoGroup Tests" { Get-SsoGroup -Name $groupName -Domain 'vsphere.local' | Should -Be $null } } + + Context "Set-SsoGroup" { + It 'Should update a SsoGroup with new description' { + # Arrange + $groupName = 'TestGroup4' + $expectedDescription = 'Test Description 4' + $groupToUpdate = New-SsoGroup -Name $groupName + + # Act + $actual = $groupToUpdate | Set-SsoGroup -Description $expectedDescription + + # Assert + $actual | Should -Not -Be $null + $script:testGroupsToDelete += $actual + $actual.Description | Should -Be $expectedDescription + } + } } \ No newline at end of file