Functions/User/New-PASGroup.ps1

function New-PASGroup {
    <#
.SYNOPSIS
Creates a vault group.

.DESCRIPTION
Adds a new Vault group.

Requires the following permissions:
- Add Users
- Update Users

.PARAMETER groupName
The name of the group to create

.PARAMETER description
A description for the group

.PARAMETER location
The vault location to create the group in.
Preceded by "\"

.EXAMPLE
New-PASGroup -groupName SomeNewGroup -description "Some Description" -location \PSP\CyberArk\Groups

Creates SomeNewGroup in the \PSP\CyberArk\Groups vault location

.EXAMPLE
New-PASGroup -groupName VaultGroup -description "Some Description" -location \

Creates VaultGroup in the root vault location
.INPUTS
All parameters can be piped by property name

.OUTPUTS
psPAS.CyberArk.Vault.Group Object

.NOTES
Minimum Version 11.1

.LINK
https://pspas.pspete.dev/commands/New-PASGroup
#>

    [CmdletBinding(SupportsShouldProcess)]
    param(
        [parameter(
            Mandatory = $true,
            ValueFromPipelinebyPropertyName = $true
        )]
        [string]$groupName,

        [parameter(
            Mandatory = $false,
            ValueFromPipelinebyPropertyName = $true
        )]
        [string]$description,

        [parameter(
            Mandatory = $false,
            ValueFromPipelinebyPropertyName = $true
        )]
        [string]$location
    )

    BEGIN {
        Assert-VersionRequirement -RequiredVersion 11.1
    }#begin

    PROCESS {

        #Create URL for request
        $URI = "$Script:BaseURI/API/UserGroups"

        #Construct Request Body
        $Body = $PSBoundParameters | Get-PASParameter | ConvertTo-Json

        if ($PSCmdlet.ShouldProcess($groupName, "Create Group")) {

            #send request to web service
            $result = Invoke-PASRestMethod -Uri $URI -Method POST -Body $Body -WebSession $Script:WebSession

        }

        If ($null -ne $result) {

            $result | Add-ObjectDetail -typename psPAS.CyberArk.Vault.Group

        }

    }#process

    END { }#end

}