add Get-MatrixJoinedMembers

This commit is contained in:
James 2022-03-31 22:19:12 +01:00
parent c16d850676
commit 5cc813f849
2 changed files with 38 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,36 @@
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 $_
}
}