Private/Get-SlackUserFromID.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
function Get-SlackUserFromID {
    [cmdletbinding()]
    param(
        [string[]]$Id,
        $UserMap
    )
    begin {
        if(-not $PSBoundParameters.ContainsKey('UserMap')){
            $UserMap = $Script:_PSSlackUserMap
            if($UserMap.Keys.Count -like 0) {
                Write-Verbose "No Slack User Map found. Please run Get-SlackUserMap -Update"
            }
        }
        $Map = @{}
        foreach($Key in $UserMap.Keys) {
            $Map.add($UserMap[$Key], $Key)
        }
    }
    process {
        if(-not $Map.Keys.count) {
            return $Id
        }
        foreach($UserID in $Id) {
            if($Map.ContainsKey($UserID)) {
                $Map[$UserID]
            }
            else {
                $UserID
            }
        }
    }
}