Modules/AzureDevOpsDsc.Common/Api/Functions/Private/Api/Group/Remove-DevOpsGroup.ps1

<#
.SYNOPSIS
Removes a group from Azure DevOps.
 
.DESCRIPTION
The Remove-DevOpsGroup function is used to remove a group from Azure DevOps using the Azure DevOps REST API.
 
.PARAMETER ApiUri
The mandatory parameter for the API URI.
 
.PARAMETER ApiVersion
The optional parameter for the API version. Defaults to '7.1-preview.1' - the graph
API is preview-only and rejects a plain '7.1'.
 
.PARAMETER GroupDescriptor
The optional parameter for the project scope descriptor.
 
.OUTPUTS
System.Management.Automation.PSObject
 
.EXAMPLE
Remove-DevOpsGroup -ApiUri "https://dev.azure.com/myorganization" -GroupDescriptor "MyGroup"
 
This example removes the group with the specified group descriptor from Azure DevOps.
 
#>

Function Remove-DevOpsGroup
{
    [CmdletBinding()]
    [OutputType([System.Management.Automation.PSObject])]
    param
    (
        [Parameter(Mandatory = $true)]
        [string]
        $ApiUri,

        [Parameter()]
        [String]
        $ApiVersion,

        [Parameter()]
        [String]
        $GroupDescriptor
    )

    # The graph API is preview-only: it rejects a plain '7.1' with
    # VssInvalidPreviewVersionException. Get-AzDevOpsApiVersion -Default returns '7.1',
    # so pin the preview version the way every other graph call in this module does.
    if (-not $ApiVersion) { $ApiVersion = '7.1-preview.1' }

    $params = @{
        Uri = '{0}/_apis/graph/groups/{1}?api-version={2}' -f $ApiUri.TrimEnd('/'), $GroupDescriptor, $ApiVersion
        Method = 'Delete'
        ContentType = 'application/json'
    }

    try
    {
        return (Invoke-AzDevOpsApiRestMethod @params)
    }
    catch
    {
        Write-Error "Failed to remove group: $_"
    }
}