Functions/LDAPDirectories/Set-PASDirectoryMappingOrder.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
function Set-PASDirectoryMappingOrder {
    <#
.SYNOPSIS
Changes the order of directory mappings for a directory

.DESCRIPTION
Updates the order of all a directories mappings.

Requires membership of Vault Admins group & "Audit users", "Add/Update users" & "Manage Directory mappings" authorizations.
Minimum version 10.10

.PARAMETER DirectoryName
The name of the directory

.PARAMETER MappingsOrder
The MappingID of each directory mapping, in the order they should be applied.

.EXAMPLE
Set-PASDirectoryMappingOrder -DirectoryName "DOMAIN.COM" -MappingsOrder 39,43,41,669,668,667

Sets the order of the directory mappings for directory "DOMAIN.COM"

.LINK
https://pspas.pspete.dev/commands/Set-PASDirectoryMappingOrder
#>


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

        [parameter(
            Mandatory = $true,
            ValueFromPipelinebyPropertyName = $true
        )]
        [int[]]$MappingsOrder
    )

    BEGIN {

        $MinimumVersion = [System.Version]"10.10"

    }#begin

    PROCESS {

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

        #Create URL for request
        $URI = "$Script:BaseURI/api/Configuration/LDAP/Directories/$DirectoryName/Mappings/Reorder"

        #Get request parameters
        $body = $($PSBoundParameters | Get-PASParameter -ParametersToRemove DirectoryName) | ConvertTo-Json

        if ($PSCmdlet.ShouldProcess($DirectoryName, "Update Directory Mapping Order")) {

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

        }

    }#process

    END { }#end

}