private/mapping/Read-ConfluenceSpacePermissionSubjects.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
function Read-ConfluenceSpacePermissionSubjects {
    [CmdletBinding()]
    param (
        # User object
        [Parameter(Mandatory,Position=0,ValueFromPipeline)]
        [AllowNull()]
        [pscustomobject]
        $Data
    )
    
    begin {
        $toReturn = @()
    }
    
    process {
        if ($null -eq $Data) { 
            $toReturn += @{
                Type = $null
                Id = $null
            }
        } else {
            if ([bool]($data.PSobject.Properties.name -match "user")) {
                $toReturn += $data.user.results | ForEach-Object { [PSCustomObject]@{
                       Type = "user"
                       Id = $_.accountId
                    }
                }
            }
            if ([bool]($data.PSobject.Properties.name -match "group")) {
                $toReturn += $data.group.results | ForEach-Object { [PSCustomObject]@{
                       Type = "group"
                       Id = $_.name
                    }
                }
            }
        }
    }
    
    end {
        $toReturn
    }
}