add optional DeviceDisplayName parameter

This commit is contained in:
James 2022-03-12 22:31:54 +00:00
parent e648d011f5
commit 605a50b713

View File

@ -11,6 +11,9 @@
.Parameter Credentials .Parameter Credentials
PSCredentials Object that contains the Matrix Username and Password for the user you wish to log in with. PSCredentials Object that contains the Matrix Username and Password for the user you wish to log in with.
.Parameter DeviceDisplayName
Display name to assign to this Access token.
.Example .Example
# Create a PSCredentials Object # Create a PSCredentials Object
$creds = Get-Credential $creds = Get-Credential
@ -22,7 +25,10 @@ function New-MatrixAccessToken {
[string]$ServerUrl, [string]$ServerUrl,
[Parameter(Mandatory)] [Parameter(Mandatory)]
[PSCredential]$Credentials [PSCredential]$Credentials,
[Parameter(Mandatory=$false)]
[string]$DeviceDisplayName="PSMatrix"
) )
$apiPath = "_matrix/client/v3/login" $apiPath = "_matrix/client/v3/login"
@ -35,7 +41,7 @@ function New-MatrixAccessToken {
} }
type = "m.login.password" type = "m.login.password"
password = $Credentials.Password | ConvertFrom-SecureString -AsPlainText password = $Credentials.Password | ConvertFrom-SecureString -AsPlainText
initial_device_display_name = "PSMatrix" initial_device_display_name = $DeviceDisplayName
} | ConvertTo-Json } | ConvertTo-Json
$res = Invoke-RestMethod -Uri "$ServerUrl/$apiPath" -Method $apiMethod -Body $reqBody $res = Invoke-RestMethod -Uri "$ServerUrl/$apiPath" -Method $apiMethod -Body $reqBody