mirror of
https://github.com/Thumbscrew/PSMatrix.git
synced 2025-01-18 09:35:44 +00:00
Get-MatrixJoinedMembers
(#1)
* add `Get-MatrixJoinedMembers` * add Get-Help section
This commit is contained in:
parent
c16d850676
commit
a0d3272f2c
@ -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.
|
||||
|
55
public/Get-MatrixJoinedMembers.ps1
Normal file
55
public/Get-MatrixJoinedMembers.ps1
Normal 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 $_
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user