Functions/User/New-PASGroup.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
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.
Preceeded 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 {
        $MinimumVersion = [System.Version]"11.1"
    }#begin

    PROCESS {

        Assert-VersionRequirement -ExternalVersion $Script:ExternalVersion -RequiredVersion $MinimumVersion

        #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 ($result) {

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

        }

    }#process

    END { }#end

}