Public/Get-SlackUserMap.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 |
function Get-SlackUserMap { <# .SYNOPSIS Get a map of Slack IDs to friendly names .DESCRIPTION Get a map of Slack IDs to friendly names .PARAMETER Token Token to use for the Slack API Default value is the value set by Set-PSSlackConfig .Parameter Update If specified, update PSSlack's cached map of names and IDs .Parameter Raw Return raw output. If specified, Name parameter is ignored .EXAMPLE Get-SlackUserMap # Get map of names to IDs from cached PSSlack data .EXAMPLE Get-SlackUserMap -Update # Get map of names to IDs from Slack, and update cached PSSlack data .FUNCTIONALITY Slack #> [cmdletbinding(DefaultParameterSetName = 'Content')] param ( [string]$Token = $Script:PSSlack.Token, [switch]$Raw, [switch]$Update ) begin { if(-not $Update) { return $Script:_PSSlackUserMap } $params = @{ Token = $Token Method = 'users.list' } if($body.keys.count -gt 0) { $params.add('body', $Body) } $RawUsers = Send-SlackApi @params $AllUsers = $RawUsers.members foreach($SlackUser in $RawUsers.members) { $UID = $SlackUser.id $Name = $SlackUser.name if($Script:_PSSlackUserMap.ContainsKey($Name)) { $Script:_PSSlackUserMap[$Name] = $UID } else { $Script:_PSSlackUserMap.add($Name, $UID) } } $Script:_PSSlackUserMap } } |