`Get-MatrixJoinedMembers` (#1)

* add `Get-MatrixJoinedMembers`

* add Get-Help section
This commit is contained in:
James 2022-03-31 22:27:27 +01:00 committed by GitHub
parent c16d850676
commit a0d3272f2c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 57 additions and 1 deletions

View File

@ -72,7 +72,8 @@ PowerShellVersion = '7.0'
FunctionsToExport = @(
'New-MatrixAccessToken',
'Remove-MatrixAccessToken',
'Get-MatrixJoinedRooms'
'Get-MatrixJoinedRooms',
'Get-MatrixJoinedMembers'
)
# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.

View File

@ -0,0 +1,55 @@
<#
.Synopsis
Get all joined members for a given Room ID.
.Description
Get all joined members for a given Room ID from _matrix/client/v3/rooms/{roomId}/joined_members. See https://spec.matrix.org/v1.2/client-server-api/#get_matrixclientv3roomsroomidjoined_members.
.Parameter ServerUrl
URL for the Matrix server to log into, for example "https://matrix.example.com".
.Parameter AccessToken
A SecureString containing the Matrix access token.
.Parameter RoomId
The Matrix room ID to retrieve joined members for.
.Example
Get-MatrixJoinedMembers -ServerUrl $server -AccessToken $token -RoomId "!ehXvUhWNASUkSLvAGP:matrix.org"
#>
function Get-MatrixJoinedMembers {
param(
[Parameter(Mandatory)]
[string]$ServerUrl,
[Parameter(Mandatory)]
[SecureString]$AccessToken,
[Parameter(Mandatory)]
[string]$RoomId
)
$url = New-MatrixUrl -ServerUrl $ServerUrl -ApiPath "_matrix/client/v3/rooms/$RoomId/joined_members"
Write-Debug "URL: $url"
$headers = Get-MatrixAuthHeaders -AccessToken $AccessToken
try {
$res = Invoke-RestMethod -Uri $url -Headers $headers
$joinedObject = $res.joined
$members = @()
$joinedObject.PSObject.Properties | ForEach-Object {
$member = [PSCustomObject]@{
MatrixId = $_.Name
DisplayName = $_.Value.display_name
AvatarUrl = $_.Value.avatar_url
}
$members += $member
}
return $members
} catch {
Write-Error $_
}
}