From bce73fc7fcbc13cd50751446417c43efab9e4687 Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Wed, 4 Sep 2024 20:43:21 +0200 Subject: [PATCH] UserGroup: Add Remove-FGTUserGroup for remove member group --- PowerFGT/Public/cmdb/user/group.ps1 | 55 +++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/PowerFGT/Public/cmdb/user/group.ps1 b/PowerFGT/Public/cmdb/user/group.ps1 index 89acacee0..124f1568c 100644 --- a/PowerFGT/Public/cmdb/user/group.ps1 +++ b/PowerFGT/Public/cmdb/user/group.ps1 @@ -198,3 +198,58 @@ function Get-FGTUserGroup { End { } } + +function Remove-FGTUserGroup { + + <# + .SYNOPSIS + Remove a FortiGate User + + .DESCRIPTION + Remove an User Group object on the FortiGate + + .EXAMPLE + $MyFGTUserGroup = Get-FGTUserGroup -name MyFGTUserGroup + PS C:\>$MyFGTUserGroup | Remove-FGTUserGroup + + Remove User Group object $MyFGTUserGroup + + .EXAMPLE + $MyFGTUserGroup = Get-FGTUserGroup -name MyFGTUserGroup + PS C:\>$MyFGTUserGroup | Remove-FGTUserGroup -confirm:$false + + Remove User object $MyFGTUserGroup with no confirmation + + #> + + [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'high')] + Param( + [Parameter (Mandatory = $true, ValueFromPipeline = $true, Position = 1)] + [ValidateScript( { Confirm-FGTUserGroup $_ })] + [psobject]$usergroup, + [Parameter(Mandatory = $false)] + [String[]]$vdom, + [Parameter(Mandatory = $false)] + [psobject]$connection = $DefaultFGTConnection + ) + + Begin { + } + + Process { + + $invokeParams = @{ } + if ( $PsBoundParameters.ContainsKey('vdom') ) { + $invokeParams.add( 'vdom', $vdom ) + } + + $uri = "api/v2/cmdb/user/group" + + if ($PSCmdlet.ShouldProcess($usergroup.name, 'Remove User Group')) { + $null = Invoke-FGTRestMethod -method "DELETE" -uri $uri -uri_escape $usergroup.name -connection $connection @invokeParams + } + } + + End { + } +} \ No newline at end of file