Public/Get-SlackUserGroup.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
function Get-SlackUserGroup {
    <#
    .SYNOPSIS
        Get Slack user groups
    .DESCRIPTION
        Get Slack user groups
    .PARAMETER Token
        Token to use for the Slack API
        Default value is the value set by Set-PSSlackConfig
    .PARAMETER IncludeUsers
        If specified, include users

        If you update the user map ahead of time, we parse user IDs to user names:
            Get-SlackUserMap -Update ahead of team
    .PARAMETER IncludeDisabled
        If specified, include disabled users
    .Parameter Raw
        Return raw output. If specified, Name parameter is ignored
    .EXAMPLE
        Get-SlackUserGroup
        # Get slack user group info
    .EXAMPLE
        $null = Get-SlackUserMap -Update
        Get-SlackUserGroup -IncludeUsers

        # Get user id to name map, pull user groups and their members
    .FUNCTIONALITY
        Slack
    #>

    [cmdletbinding()]
    param (
        [string]$Token = $Script:PSSlack.Token,
        [switch]$IncludeUsers,
        [switch]$IncludeDisabled,
        [switch]$Raw
    )
    begin
    {
        Write-Verbose "$($PSBoundParameters | Remove-SensitiveData | Out-String)"
        $body = @{}
        if($IncludeUsers) {
            $body.add('include_users',$true)
        }
        if($IncludeDisabled) {
            $body.add('include_disabled',$true)
        }

        $params = @{
            Token = $Token
            Method = 'usergroups.list'
        }
        if($body.keys.count -gt 0) {
            $params.add('body',$body)
        }

        $RawGroups = Send-SlackApi @params
        if($Raw) {
            $RawGroups
        }
        else {
            Parse-SlackUserGroup -InputObject $RawGroups.usergroups
        }
    }
}