Azure / Azure/azure-powershell
[Feature]: Send-AzWvdUserSessionMessage to utilise Id property from Get-AzWvdUserSession
- Dominant language
- C#
- Stars
- 4.8k
- Forks
- 4.3k
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 51
Description
### Description of the new feature
Currently, use of Send-AzWvdUserSessionMessage is a touch cumbersome. In order to run it, you need to first get (at least) a session id from `Get-AzWvdUserSession -ResourceGroupName RGNAME -HostPoolName HOSTPOOLNAME`. Example returned object:
```
ActiveDirectoryUserName : DOMAIN\user
ApplicationType : Desktop
CreateTime : 12/05/2022 11:18:58
Id : /subscriptions/GUID/resourcegroups/RGNAME/providers/Microsoft.DesktopVirtualization/hostpools/HOSTPOOLNAME/sessionhosts/SESSIONHOSTNAME.domain.com/usersessions/6
Name : HOSTPOOLNAME/SESSIONHOSTNAME.domain.com/6
ObjectId : 00000000-0000-0000-0000-000000000000
SessionState : Active
Type : Microsoft.DesktopVirtualization/hostpools/sessionhosts/usersessions
UserPrincipalName : user@domain.com
```
Based on this output (noting the absense of properties for `UserSessionId` or `SessionHostName`), an example of what must be then provided to send a message to a single user:
`Send-AzWvdUserSessionMessage -ResourceGroupName RGNAME -HostPoolName HOSTPOOLNAME -SessionHostName SESSIONHOSTNAME.domain.com -UserSessionId 6 -MessageTitle 'This is a message from PowerShell' -messagebody 'Hello!'`
This requires parsing properties from the output of `Get-AzWvdUserSession` for the UserSessionId and SessionHostName.
### Proposed implementation details (optional)
The `Id` property on the object returned from `Get-AzWvdUserSession` contains enough data to pipe to `Send-AzWvdUserSessionMessage`; it contains the resource group name, the host pool name, the session host name and the id of the session.
To send a message to all users:
`Get-AzWvdUserSession -ResourceGroupName RGNAME -HostPoolName HOSTPOOLNAME | Send-AzWvdUserSessionMessage -MessageTitle 'This is a message from PowerShell' -messagebody 'Hello!'`
Failing pipeline support, an additional property could be added to the `Send` cmdlet, that accepts the `Id` value from the `Get` cmdlet.
`Get-AzWvdUserSession -ResourceGroupName RGNAME -HostPoolName HOSTPOOLNAME | Foreach-Object { Send-AzWvdUserSessionMessage -NewPropertyName $_.Id -MessageTitle 'This is a message from PowerShell' -messagebody 'Hello!' }`
Contributor guide
Assessment
This issue has not been assessed yet.