Public/Get-RyverUserMap.ps1
function Get-RyverUserMap { <# .SYNOPSIS Get a map of Ryver IDs to friendly names. .DESCRIPTION Get a map of Ryver IDs to friendly names. .INPUTS None You cannot pipe input to this cmdlet. .NOTES - Troy Lindsay - Twitter: @troylindsay42 - GitHub: tlindsay42 .EXAMPLE Get-RyverUserMap Get map of names to IDs from cached PSRyver data. .EXAMPLE Get-RyverUserMap -Update Get map of names to IDs from Ryver, and update cached PSRyver data. .LINK https://tlindsay42.github.io/PSRyver/Public/Get-RyverUserMap/ .LINK https://github.com/tlindsay42/PSRyver/blob/master/PSRyver/Public/Get-RyverUserMap.ps1 .FUNCTIONALITY Ryver #> [CmdletBinding( HelpUri = 'https://tlindsay42.github.io/PSRyver/Public/Get-RyverUserMap/' )] param ( # If specified, update PSRyver's cached map of names and IDs. [Parameter( Position = 0 )] [Switch] $Update, # Return raw output. If specified, Name parameter is ignored. [Parameter( Position = 1 )] [Switch] $Raw, # The API token to use when communicating with the Ryver API. [Parameter( Position = 1 )] [PSCredential] $Credential ) begin { $function = $MyInvocation.MyCommand.Name Write-Verbose -Message ( "Beginning: '${function}' with ParameterSetName '$( $PSCmdlet.ParameterSetName )' and Parameters: " + ( $PSBoundParameters | Remove-SensitiveData | Format-Table -AutoSize | Out-String ) ) if ( $PSBoundParameters.ContainsKey( 'Credential' ) ) { $Script:PSRyver.Authorization = ConvertTo-Authorization -Credential $Credential Remove-Variable -Name 'Credential' } } process { if ( $Update -eq $true ) { $params = @{ Method = 'Post' } # $rawUsers = Invoke-RyverRestMethod @params foreach ( $ryverUser in $rawUsers.Members ) { if ( $Script:PSRyverUserMap.ContainsKey( $ryverUser.Name ) ) { $Script:PSRyverUserMap[$ryverUser.Name] = $ryverUser.ID } else { $Script:PSRyverUserMap.Add( $ryverUser.Name, $ryverUser.ID ) } } } $Script:PSRyverUserMap } end { Write-Verbose -Message "Ending: '${function}'." } } |